-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitSet.easy
More file actions
150 lines (129 loc) · 2.93 KB
/
bitSet.easy
File metadata and controls
150 lines (129 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright (C) 2021 Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"control" useFile
"algorithm" useFile
BitSet: [{
BITSET: ();
getSize:;
dataSize: getSize 31 + 32 /;
data: 0n32 dataSize array;
at: [
index:;
index 0 < index getSize < ~ or [
0 .INVALID_INDEX
] when
subIndex: index 5 rshift;
bit: index 31 and;
mask: 1n32 bit lshift;
subIndex data @ mask and 0n32 = ~
] func;
clear: [dataSize [0n32 i data !] times] func;
none: [
TRUE
dataSize 0 > [
i: 0;
[
i data @ 0n32 = [
i 1 + !i i dataSize <
] [
drop FALSE FALSE
] if
] loop
] when
] func;
any: [none ~] func;
all: [
lastBits: getSize 31 and;
lastMask: lastBits 0 = [0xFFFFFFFFn32] [1n32 lastBits lshift 1n32 -] if;
TRUE
dataSize 0 > [
dataSize 1 > [
i: 0;
[
i data @ 0xFFFFFFFFn32 = [
i 1 + !i i dataSize 1 - <
] [
drop FALSE FALSE
] if
] loop
] when
# if result
[
dataSize 1 - data @ lastMask =
] [
FALSE
] if
] when
] func;
set: [
index:;
index 0 < ~ index getSize < and
] [
value:index:;;
subIndex: index 5 rshift;
bit: index 31 and;
mask: 1n32 bit lshift;
subIndex data @ value [mask or] [0xFFFFFFFFn32 mask - and] if subIndex data !
] pfunc;
or=: [
.getSize getSize =
] [
other:;
dataSize [
i data @ i other.data @ or i data !
] times
] pfunc;
and=: [
.getSize getSize =
] [
other:;
dataSize [
i data @ i other.data @ and i data !
] times
] pfunc;
xor=: [
.getSize getSize =
] [
other:;
dataSize [
i data @ i other.data @ xor i data !
] times
] pfunc;
}] func;
makeBitSet: [
data:result: BitSet;;
data range [TRUE swap result.set TRUE] enum
result
] func;
copy: ["BITSET" has] [
src:;
dst: src.getSize BitSet;
src.data copy dst.!data
dst
] pfunc;
@: ["BITSET" has] [.at] pfunc;
!: ["BITSET" has] [.set] pfunc;
or: ["BITSET" has] [r: copy; r.or= r] pfunc;
and: ["BITSET" has] [r: copy; r.and= r] pfunc;
xor: ["BITSET" has] [r: copy; r.xor= r] pfunc;
fieldCount: ["BITSET" has] [.getSize] pfunc;
=: ["BITSET" has] [
set1:set2:;;
set1.getSize set2.getSize = ~ [
FALSE
] [
i: 0;
result: TRUE;
[i set1.dataSize < result and] [
i set1.data @ i set2.data @ = ~ [
FALSE !result
] when
i 1 + !i
] while
result
] if
] pfunc;