/[eiffelstudio]/FreeELKS/trunk/library/support/bool_string.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/support/bool_string.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91469 - (show annotations)
Tue Feb 21 14:54:50 2006 UTC (13 years, 11 months ago) by ericb
File size: 3994 byte(s)
Synchronized with ISE 5.7.0414.
Implemented BOOL_STRING in pure Eiffel.

1 indexing
2
3 description:
4 "Packed boolean strings"
5
6 library: "Free implementation of ELKS library"
7 copyright: "Copyright (c) 2005, Eiffel Software and others"
8 license: "Eiffel Forum License v2 (see forum.txt)"
9 names: packed_booleans;
10 access: index;
11 representation: array;
12 size: fixed;
13 date: "$Date$"
14 revision: "$Revision$"
15
16 class BOOL_STRING inherit
17
18 TO_SPECIAL [BOOLEAN]
19 export
20 {NONE} all
21 {BOOL_STRING} area
22 redefine
23 item, infix "@", put, valid_index
24 end
25
26 ANY
27
28 create
29
30 make
31
32 feature -- Initialization
33
34 make (n: INTEGER) is
35 -- Allocate area of `n' booleans.
36 require
37 non_negative_size: n >= 0
38 do
39 make_area (n)
40 ensure
41 correct_allocation: count = n
42 end
43
44 feature -- Access
45
46 item alias "[]", infix "@" (i: INTEGER): BOOLEAN assign put is
47 -- Boolean at `i'-th position,
48 -- beginning at left, 1 origin
49 do
50 Result := area.item (i - 1)
51 end
52
53 feature -- Status report
54
55 valid_index (i: INTEGER): BOOLEAN is
56 -- Is `i' within the bounds of Current?
57 do
58 Result := (1 <= i) and then (i <= count)
59 end
60
61 feature -- Measurement
62
63 count: INTEGER is
64 -- Number of boolean in the area.
65 do
66 Result := area.count
67 end
68
69 feature -- Element change
70
71 put (v: like item; i: INTEGER) is
72 -- Put boolean `v' at `i'-th position
73 -- beginning at left, 1 origin.
74 do
75 area.put (v, i - 1)
76 end
77
78 all_true is
79 -- Set all booleans to true.
80 do
81 area.fill_with (True, 0, count - 1)
82 end
83
84 all_false is
85 -- Set all booleans to false.
86 do
87 area.fill_with (False, 0, count - 1)
88 end
89
90 feature -- Basic operations
91
92 infix "and" (other: like Current): like Current is
93 -- Logical and of 'Current' and `other'
94 require
95 other_not_void: other /= Void
96 same_size: other.count = count
97 local
98 other_area, result_area: like area
99 i: INTEGER
100 do
101 create Result.make (count)
102 result_area := Result.area
103 other_area := other.area
104 from i := count - 1 until i < 0 loop
105 result_area.put (area.item (i) and other_area.item (i), i)
106 i := i - 1
107 end
108 end
109
110 infix "or" (other: like Current): like Current is
111 -- Logical or of 'Current' and `other'
112 require
113 other_not_void: other /= Void
114 same_size: other.count = count
115 local
116 other_area, result_area: like area
117 i: INTEGER
118 do
119 create Result.make (count)
120 result_area := Result.area
121 other_area := other.area
122 from i := count - 1 until i < 0 loop
123 result_area.put (area.item (i) or other_area.item (i), i)
124 i := i - 1
125 end
126 end
127
128 infix "xor" (other: like Current): like Current is
129 -- Logical exclusive or of 'Current' and `other'
130 require
131 other_not_void: other /= Void
132 same_size: other.count = count
133 local
134 other_area, result_area: like area
135 i: INTEGER
136 do
137 create Result.make (count)
138 result_area := Result.area
139 other_area := other.area
140 from i := count - 1 until i < 0 loop
141 result_area.put (area.item (i) xor other_area.item (i), i)
142 i := i - 1
143 end
144 end
145
146 prefix "not": like Current is
147 -- Negation of 'Current'
148 local
149 result_area: like area
150 i: INTEGER
151 do
152 create Result.make (count)
153 result_area := Result.area
154 from i := count - 1 until i < 0 loop
155 result_area.put (not area.item (i), i)
156 i := i - 1
157 end
158 end
159
160 right_shifted (n: INTEGER): like Current is
161 -- Right shifted 'Current' set, by `n' positions
162 require
163 non_negative_shift: n >= 0
164 local
165 result_area: like area
166 shift_count: INTEGER
167 do
168 create Result.make (count)
169 result_area := Result.area
170 shift_count := count - n
171 if shift_count > 0 then
172 result_area.copy_data (area, 0, n, shift_count)
173 end
174 end
175
176 left_shifted (n: INTEGER): like Current is
177 -- Left shifted 'Current' set, by `n' positions
178 require
179 non_negative_shift: n >= 0
180 local
181 result_area: like area
182 shift_count: INTEGER
183 do
184 create Result.make (count)
185 result_area := Result.area
186 shift_count := count - n
187 if shift_count > 0 then
188 result_area.copy_data (area, n, 0, shift_count)
189 end
190 end
191
192 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23