/[eiffelstudio]/trunk/eweasel/tests/incr071/resizable.e
ViewVC logotype

Contents of /trunk/eweasel/tests/incr071/resizable.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65297 - (show annotations)
Thu Nov 30 20:22:33 2006 UTC (13 years ago) by manus
File size: 2411 byte(s)
Moved from trunk/Src/eweasel to trunk/eweasel so that a simple checkout of the source code is not penalized by the lenghty process of checking out all the tests of eweasel.
1 indexing
2
3 description:
4 "Finite structures whose item count is subject to change";
5
6 status: "See notice at end of class";
7 names: storage;
8 size: resizable;
9 date: "$Date$";
10 revision: "$Revision$"
11
12 deferred class RESIZABLE [G] inherit
13
14 BOUNDED [G];
15
16 feature -- Measurement
17
18
19 Growth_percentage: INTEGER is 50;
20 -- Percentage by which structure will grow automatically
21
22 Minimal_increase: INTEGER is 5;
23 -- Minimal number of additional items
24
25 additional_space: INTEGER is
26 -- Proposed number of additional items
27 --| Result is a reasonable value, resulting from a space-time tradeoff.
28 do
29 Result := (capacity * Growth_percentage // 100).max (Minimal_increase)
30 ensure
31 At_least_one: Result >= 1
32 end;
33
34 feature -- Status report
35
36 resizable: BOOLEAN is
37 -- May `capacity' be changed? (Answer: yes.)
38 do
39 Result := true
40 end;
41
42 feature -- Resizing
43
44 automatic_grow is
45 -- Change the capacity to accommodate at least
46 -- `Growth_percentage' more items.
47 --| Trades space for time:
48 --| allocates fairly large chunks of memory but not very often.
49 do
50 grow (capacity + additional_space)
51 ensure
52 increased_capacity:
53 capacity >= old capacity + old capacity * Growth_percentage // 100
54 end;
55
56 grow (i: INTEGER) is
57 -- Ensure that capacity is at least `i'.
58 deferred
59 ensure
60 new_capacity: capacity >= i
61 end;
62
63 invariant
64
65 increase_by_at_least_one: Minimal_increase >= 1
66
67 end -- class RESIZABLE
68
69 --|----------------------------------------------------------------
70 --| EiffelBase: Library of reusable components for Eiffel.
71 --| Copyright (c) 1993-2006 University of Southern California and contributors.
72 --| For ISE customers the original versions are an ISE product
73 --| covered by the ISE Eiffel license and support agreements.
74 --| EiffelBase may now be used by anyone as FREE SOFTWARE to
75 --| develop any product, public-domain or commercial, without
76 --| payment to ISE, under the terms of the ISE Free Eiffel Library
77 --| License (IFELL) at http://eiffel.com/products/base/license.html.
78 --|
79 --| Interactive Software Engineering Inc.
80 --| ISE Building, 2nd floor
81 --| 270 Storke Road, Goleta, CA 93117 USA
82 --| Telephone 805-685-1006, Fax 805-685-6869
83 --| Electronic mail <info@eiffel.com>
84 --| Customer support e-mail <support@eiffel.com>
85 --| For latest info see award-winning pages: http://eiffel.com
86 --|----------------------------------------------------------------
87

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23