forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitset.ts
More file actions
38 lines (36 loc) · 792 Bytes
/
bitset.ts
File metadata and controls
38 lines (36 loc) · 792 Bytes
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
/** @module util *//***/
/** Tests if the bit at the specified index is set within a 64-bit map. */
export function bitsetIs(map: I64, index: i32): bool {
assert(index >= 0 && index < 64);
return i64_ne(
i64_and(
map,
i64_shl(
i64_one,
i64_new(index)
)
),
i64_zero
);
}
/** Sets or unsets the bit at the specified index within a 64-bit map and returns the new map. */
export function bitsetSet(map: I64, index: i32, isSet: bool): I64 {
assert(index >= 0 && index < 64);
return isSet
? i64_or(
map,
i64_shl(
i64_one,
i64_new(index)
)
)
: i64_and(
map,
i64_not(
i64_shl(
i64_one,
i64_new(index)
)
)
);
}