2
$Id: genset.inc,v 1.7 2002/09/07 15:07:45 peter Exp $
3
This file is part of the Free Pascal run time library.
4
Copyright (c) 1999-2001 by the Free Pascal development team
6
Include file with set operations called by the compiler
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
17
{$ifndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
18
{ Error No pascal version of FPC_SET_LOAD_SMALL}
19
{ THIS DEPENDS ON THE ENDIAN OF THE ARCHITECTURE!
22
function fpc_set_load_small(l: fpc_small_set): fpc_normal_set; [public,alias:'FPC_SET_LOAD_SMALL']; {$ifdef hascompilerproc} compilerproc; {$endif}
24
load a normal set p from a smallset l
27
fpc_set_load_small[0] := l;
28
FillDWord(fpc_set_load_small[1],7,0);
30
{$endif FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
33
{$ifndef FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
34
function fpc_set_create_element(b : byte): fpc_normal_set;[public,alias:'FPC_SET_CREATE_ELEMENT']; {$ifdef hascompilerproc} compilerproc; {$endif}
36
create a new set in p from an element b
39
FillDWord(fpc_set_create_element,SizeOf(fpc_set_create_element) div 4,0);
40
fpc_set_create_element[b div 32] := 1 shl (b mod 32);
42
{$endif FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
44
{$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
46
{$ifdef hascompilerproc}
47
function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
49
add the element b to the set "source"
54
move(source,fpc_set_set_byte,sizeof(source));
55
c := fpc_set_set_byte[b div 32];
56
c := (1 shl (b mod 32)) or c;
57
fpc_set_set_byte[b div 32] := c;
59
{$else hascompilerproc}
60
procedure do_set_byte(p : pointer;b : byte);[public,alias:'FPC_SET_SET_BYTE'];
62
add the element b to the set pointed by p
67
c := fpc_normal_set(p^)[b div 32];
68
c := (1 shl (b mod 32)) or c;
69
fpc_normal_set(p^)[b div 32] := c;
71
{$endif hascompilerproc}
72
{$endif FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
75
{$ifndef FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
77
{$ifdef hascompilerproc}
78
function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
80
suppresses the element b to the set pointed by p
81
used for exclude(set,element)
86
move(source,fpc_set_unset_byte,sizeof(source));
87
c := fpc_set_unset_byte[b div 32];
88
c := c and not (1 shl (b mod 32));
89
fpc_set_unset_byte[b div 32] := c;
91
{$else hascompilerproc}
92
procedure do_unset_byte(p : pointer;b : byte);[public,alias:'FPC_SET_UNSET_BYTE'];
94
suppresses the element b to the set pointed by p
95
used for exclude(set,element)
100
c := fpc_normal_set(p^)[b div 32];
101
c := c and not (1 shl (b mod 32));
102
fpc_normal_set(p^)[b div 32] := c;
104
{$endif hascompilerproc}
105
{$endif FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
108
{$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
109
{$ifdef hascompilerproc}
110
function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set; compilerproc;
112
adds the range [l..h] to the set orgset
118
move(orgset,fpc_set_set_range,sizeof(orgset));
121
c := fpc_set_set_range[i div 32];
122
c := (1 shl (i mod 32)) or c;
123
fpc_set_set_range[i div 32] := c;
126
{$else hascompilerproc}
127
procedure do_set_range(p : pointer;l,h : byte);[public,alias:'FPC_SET_SET_RANGE'];
129
bad implementation, but it's very seldom used
137
c := fpc_normal_set(p^)[i div 32];
138
c := (1 shl (i mod 32)) or c;
139
fpc_normal_set(p^)[i div 32] := c;
142
{$endif hascompilerproc}
143
{$endif ndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
146
{$ifndef FPC_SYSTEM_HAS_FPC_SET_IN_BYTE}
148
function fpc_set_in_byte(const p: fpc_normal_set; b: byte): boolean; [public,alias:'FPC_SET_IN_BYTE']; {$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
150
tests if the element b is in the set p the carryflag is set if it present
153
fpc_set_in_byte := (p[b div 32] and (1 shl (b mod 32))) <> 0;
158
{$ifndef FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
159
{$ifdef hascompilerproc}
160
function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_ADD_SETS']; compilerproc;
162
dest: fpc_normal_set absolute fpc_set_add_sets;
163
{$else hascompilerproc}
164
procedure do_add_sets(const set1,set2: fpc_normal_Set; var dest : fpc_normal_set);[public,alias:'FPC_SET_ADD_SETS'];
165
{$endif hascompilerproc}
167
adds set1 and set2 into set dest
173
dest[i] := set1[i] or set2[i];
178
{$ifndef FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
179
{$ifdef hascompilerproc}
180
function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_MUL_SETS']; compilerproc;
182
dest: fpc_normal_set absolute fpc_set_mul_sets;
183
{$else hascompilerproc}
184
procedure do_mul_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_MUL_SETS'];
185
{$endif hascompilerproc}
187
multiplies (takes common elements of) set1 and set2 result put in dest
193
dest[i] := set1[i] and set2[i];
198
{$ifndef FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
199
{$ifdef hascompilerproc}
200
function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SUB_SETS']; compilerproc;
202
dest: fpc_normal_set absolute fpc_set_sub_sets;
203
{$else hascompilerproc}
204
procedure do_sub_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SUB_SETS'];
205
{$endif hascompilerproc}
207
computes the diff from set1 to set2 result in dest
213
dest[i] := set1[i] and not set2[i];
218
{$ifndef FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
219
{$ifdef hascompilerproc}
220
function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SYMDIF_SETS']; compilerproc;
222
dest: fpc_normal_set absolute fpc_set_symdif_sets;
223
{$else hascompilerproc}
224
procedure do_symdif_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SYMDIF_SETS'];
225
{$endif hascompilerproc}
227
computes the symetric diff from set1 to set2 result in dest
233
dest[i] := set1[i] xor set2[i];
237
{$ifndef FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
238
function fpc_set_comp_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_COMP_SETS'];{$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
240
compares set1 and set2 zeroflag is set if they are equal
245
fpc_set_comp_sets:= false;
247
if set1[i] <> set2[i] then
249
fpc_set_comp_sets:= true;
255
{$ifndef FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
256
function fpc_set_contains_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_CONTAINS_SETS'];{$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
258
on exit, zero flag is set if set1 <= set2 (set2 contains set1)
263
fpc_set_contains_sets:= false;
265
if (set1[i] and not set2[i]) <> 0 then
267
fpc_set_contains_sets:= true;
273
Revision 1.7 2002/09/07 15:07:45 peter
274
* old logs removed and tabs fixed