Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6732 | leency | 1 | |
2 | |||
3 | int Delta;//increase buffer Delta |
||
4 | int Items;//pointer to array of item pointers |
||
5 | int Limit;//currently allocated size (in elements) of Items list |
||
6 | |||
7 | TCollection( int ALimit,ADelta ); |
||
8 | |||
9 | |||
10 | int At( int Index ); |
||
11 | |||
12 | void AtFree( int Index ); |
||
13 | void AtInsert( int Index, Item ); |
||
14 | void DeleteAll( void ); |
||
15 | void Free( int Item ); |
||
16 | void FreeAll( void ); |
||
17 | void FreeItem( int Item ); |
||
18 | void Insert( int Item ); |
||
19 | void SetLimit( int ALimit ); |
||
20 | }; |
||
21 | |||
22 | :int TCollection::At( int Index ) |
||
23 | |||
24 | return DSDWORD[ Index*sizeof(int)+Items ]; |
||
25 | } |
||
26 | |||
27 | :void TCollection::AtDelete( int Index ) |
||
28 | |||
29 | // if(Index<0)||(Index>=Count){/*Error(coIndexError);*/return;} |
||
30 | ECX = Count-Index-1; |
||
31 | EDI = Index*sizeof(int)+Items; ESI = EDI+4; $cld; $rep;$movsd; |
||
32 | Count --; |
||
33 | } |
||
34 | |||
35 | :void TCollection::AtFree( int Index ) |
||
36 | |||
37 | int Item = At( Index); |
||
38 | AtDelete( Index ); |
||
39 | FreeItem( Item ); |
||
40 | } |
||
41 | |||
42 | :void TCollection::AtInsert( int Index, Item ) |
||
43 | |||
44 | $pushfd |
||
45 | IF( Count == Limit ) |
||
46 | { |
||
47 | SetLimit( Count+Delta ); |
||
48 | } |
||
49 | ECX = Count-Index; |
||
50 | EDI = Count*sizeof(int)+Items; |
||
51 | ESI = EDI-4; $std $rep $movsd $cld |
||
52 | DSDWORD[ EDI ] = Item; |
||
53 | Count ++; |
||
54 | $popfd |
||
55 | } |
||
56 | |||
57 | :void TCollection::DeleteAll() |
||
58 | |||
59 | Count=0; |
||
60 | } |
||
61 | |||
62 | :void TCollection::Free( int Item ) |
||
63 | |||
64 | Delete( Item ); |
||
65 | FreeItem( Item ); |
||
66 | } |
||
67 | |||
68 | :void TCollection::FreeAll( void ) |
||
69 | |||
70 | int I; |
||
71 | FOR( I = 0; I < Count; I ++ )FreeItem( At(I) ); |
||
72 | Count = 0; |
||
73 | } |
||
74 | |||
75 | :void TCollection::FreeItem( int Item ) |
||
76 | |||
77 | IF( Item )free( Item );//+++Dispose(PObject(Item), Done); |
||
78 | } |
||
79 | |||
80 | :void TCollection::Insert( int Item ) |
||
81 | |||
82 | AtInsert( Count, Item ); |
||
83 | } |
||
84 | |||
85 | :void TCollection::SetLimit( int ALimit ) |
||
86 | |||
87 | int AItems; |
||
88 | |||
89 | IF( ALimit < Count )ALimit = Count; |
||
90 | |||
91 | { |
||
92 | IF( !ALimit ) AItems = 0; |
||
93 | ELSE |
||
94 | { |
||
95 | AItems = malloc(ALimit*sizeof(int) ); |
||
96 | IF( Count )&&( Items ) |
||
97 | { |
||
98 | CopyMemory( AItems, Items, Limit*sizeof(int) ); |
||
99 | } |
||
100 | } |
||
101 | IF( Limit )free( Items ); |
||
102 | Items = AItems; |
||
103 | Limit = ALimit; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | :TCollection::TCollection( int ALimit, ADelta ) |
||
108 | |||
109 | Items = 0; |
||
110 | Count = 0; |
||
111 | Limit = 0; |
||
112 | Delta = ADelta; |
||
113 | SetLimit( ALimit ); |
||
114 | return this; |
||
115 | } |
||
116 | |||
117 | :TCollection::~TCollection( void ) |
||
118 | |||
119 | FreeAll(); |
||
120 | SetLimit(0); |
||
121 | } |
||
122 | |||
123 | struct TSortedCollection:TCollection |
||
124 | |||
125 | int comparemethod; |
||
126 | int Duplicates; |
||
127 | |||
128 | TSortedCollection( int ALimit, ADelta ); |
||
129 | |||
130 | int Compare( int Key1, Key2 ); |
||
131 | |||
132 | int Search( int Key, Index ); |
||
133 | }; |
||
134 | |||
135 | :int TSortedCollection::Compare( int Key1, Key2 ) |
||
136 | |||
137 | strcmp( Key1, Key2 ); |
||
138 | } |
||
139 | |||
140 | :TSortedCollection::TSortedCollection( int ALimit, ADelta ) |
||
141 | |||
142 | { |
||
143 | comparemethod=#Compare; |
||
144 | return this; |
||
145 | } |
||
146 | |||
147 | :void TSortedCollection::Insert( int Item ) |
||
148 | |||
149 | int i; |
||
150 | IF( !Search(/*KeyOf(*/Item/*)*/,#i) ) || ( Duplicates )AtInsert( i, Item ); |
||
151 | } |
||
152 | |||
153 | |||
154 | |||
155 | |||
156 | int L, H, I, C; |
||
157 | int S; |
||
158 | |||
159 | S = 0; |
||
160 | |||
161 | H = Count-1; |
||
162 | WHILE( L <= H ) |
||
163 | { |
||
164 | I = L+H >> 1; |
||
165 | ECX = I*sizeof(int)+Items; |
||
166 | comparemethod( this, /*KeyOf(*/DSDWORD[ECX]/*)*/, Key ); |
||
167 | C = EAX; |
||
168 | IF( C < 0 ){ L = I+1; } |
||
169 | ELSE |
||
170 | { |
||
171 | H = I-1; |
||
172 | IF( !C ){ |
||
173 | S = 1; |
||
174 | IF( !Duplicates )L = I; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | DSDWORD[ Index ]=L; |
||
179 | return S; |
||
180 | }>=>>>0)||(Index> |
||
181 |