Skip to content

Commit 71ccedd

Browse files
committed
add hash set type
1 parent 6915625 commit 71ccedd

File tree

4 files changed

+934
-0
lines changed

4 files changed

+934
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {make as makeStructType} from "./type-class/struct-type";
77
import {make as makeObjectType} from "./type-class/object-type";
88
import {make as makeArrayType} from "./type-class/array-type";
99
import {make as makeHashMapType} from "./type-class/hash-map-type";
10+
import {make as makeHashSetType} from "./type-class/hash-set-type";
1011

1112
import {make as makeStringPool} from "./string-pool";
1213

@@ -41,6 +42,7 @@ export class Realm {
4142
ArrayType: Class<TypeClass<ArrayType<any>>>;
4243
StringType: Class<TypeClass<PrimitiveType<string>>>;
4344
HashMapType: Class<TypeClass<HashMapType<any, any>>>;
45+
HashSetType: Class<TypeClass<HashSetType<any, any>>>;
4446

4547
T: {
4648
[name: string|Symbol]: Type;
@@ -68,6 +70,7 @@ export class Realm {
6870
this.ArrayType = makeArrayType(this);
6971
this.StringType = makeStringType(this);
7072
this.HashMapType = makeHashMapType(this);
73+
this.HashSetType = makeHashSetType(this);
7174
this.isInitialized = false;
7275
}
7376

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# HashSetType
2+
3+
A type class for typed hash sets. Takes an element type as input and produces a hash set type which can store elements of that type.
4+
5+
Usage:
6+
7+
```js
8+
const {HashSetType, T} = realm;
9+
10+
const StringSet = new HashSetType(T.String);
11+
12+
const set = new StringSet();
13+
14+
set.add('hello world');
15+
set.add('foo bar');
16+
17+
set.has('hello world'); // true
18+
19+
for (const entry of set) {
20+
console.log(entry);
21+
}
22+
23+
set.delete('foo bar');
24+
```

0 commit comments

Comments
 (0)