Skip to content

Commit 1e60ab2

Browse files
cleanup and optimizations, set interface compliance
1 parent 0f1a009 commit 1e60ab2

14 files changed

+374
-41
lines changed

.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
"type_traits": "cpp",
105105
"memory": "cpp",
106106
"__functional_base_03": "cpp",
107-
"__tuple": "cpp"
107+
"__tuple": "cpp",
108+
"__functional_03": "cpp",
109+
"ostream": "cpp"
108110
}
109111
}

benchmarks/iterator.bench.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bench.suite('iterator', (suite) => {
1414

1515
suite.scope(() => {
1616
const x = new Set(data)
17-
suite.benchmark('Set', () => {
17+
suite.benchmark('Set.iterator', () => {
1818
let n = 0
1919
for (const j of x) {
2020
n += j
@@ -23,16 +23,38 @@ bench.suite('iterator', (suite) => {
2323
})
2424
})
2525

26+
suite.scope(() => {
27+
const x = new Set(data)
28+
suite.benchmark('Set.forEach', () => {
29+
let n = 0
30+
x.forEach((v) => {
31+
n += v
32+
})
33+
return n
34+
})
35+
})
36+
2637
suite.scope(() => {
2738
const x = new RoaringBitmap32(data)
28-
suite.benchmark('RoaringBitmap32', () => {
39+
suite.benchmark('RoaringBitmap32.iterator', () => {
2940
let n = 0
3041
for (const j of x) {
3142
n += j
3243
}
3344
return n
3445
})
3546
})
47+
48+
suite.scope(() => {
49+
const x = new RoaringBitmap32(data)
50+
suite.benchmark('RoaringBitmap32.forEach', () => {
51+
let n = 0
52+
x.forEach((v) => {
53+
n += v
54+
})
55+
return n
56+
})
57+
})
3658
})
3759

3860
if (require.main === module) {

documentation/api/index.d.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The iterator may throw exception if the bitmap is changed during the iteration.
103103
### CRoaringVersion
104104
105105
Property: The version of the CRoaring libary as a string.
106-
Example: "0.2.42"
106+
Example: "0.4.0"
107107
108108
```typescript
109109
var CRoaringVersion: string
@@ -118,7 +118,7 @@ string
118118
### PackageVersion
119119
120120
Property: The version of the roaring npm package as a string.
121-
Example: "0.2.2"
121+
Example: "1.2.0"
122122
123123
```typescript
124124
var PackageVersion: string

documentation/api/index.d/roaringbitmap32.md

+72-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@
7171
- [contentToString(maxLength)][methoddeclaration-66]
7272
- [statistics()][methoddeclaration-67]
7373
- Properties
74-
- [size][propertydeclaration-0]
75-
- [isEmpty][propertydeclaration-1]
74+
- [CRoaringVersion][propertydeclaration-0]
75+
- [CRoaringVersion][propertydeclaration-2]
76+
- [PackageVersion][propertydeclaration-1]
77+
- [PackageVersion][propertydeclaration-3]
78+
- [size][propertydeclaration-4]
79+
- [isEmpty][propertydeclaration-5]
7680

7781
# RoaringBitmap32
7882

@@ -1627,6 +1631,66 @@ public statistics(): RoaringBitmap32Statistics;
16271631
16281632
## Properties
16291633
1634+
### CRoaringVersion
1635+
1636+
Property: The version of the CRoaring libary as a string.
1637+
Example: "0.4.0"
1638+
1639+
```typescript
1640+
public static readonly CRoaringVersion: string;
1641+
```
1642+
1643+
**Type**
1644+
1645+
string
1646+
1647+
---
1648+
1649+
### CRoaringVersion
1650+
1651+
Property: The version of the CRoaring libary as a string.
1652+
Example: "0.4.0"
1653+
1654+
```typescript
1655+
public readonly CRoaringVersion: string;
1656+
```
1657+
1658+
**Type**
1659+
1660+
string
1661+
1662+
---
1663+
1664+
### PackageVersion
1665+
1666+
Property: The version of the roaring npm package as a string.
1667+
Example: "1.2.0"
1668+
1669+
```typescript
1670+
public static readonly PackageVersion: string;
1671+
```
1672+
1673+
**Type**
1674+
1675+
string
1676+
1677+
---
1678+
1679+
### PackageVersion
1680+
1681+
Property: The version of the roaring npm package as a string.
1682+
Example: "1.2.0"
1683+
1684+
```typescript
1685+
public readonly PackageVersion: string;
1686+
```
1687+
1688+
**Type**
1689+
1690+
string
1691+
1692+
---
1693+
16301694
### size
16311695
16321696
Property. Gets the number of items in the set (cardinality).
@@ -1778,5 +1842,9 @@ boolean
17781842
[methoddeclaration-66]: roaringbitmap32.md#contenttostringmaxlength
17791843
[methoddeclaration-67]: roaringbitmap32.md#statistics
17801844
[interfacedeclaration-1]: ../index.d.md#roaringbitmap32statistics
1781-
[propertydeclaration-0]: roaringbitmap32.md#size
1782-
[propertydeclaration-1]: roaringbitmap32.md#isempty
1845+
[propertydeclaration-0]: roaringbitmap32.md#croaringversion
1846+
[propertydeclaration-2]: roaringbitmap32.md#croaringversion
1847+
[propertydeclaration-1]: roaringbitmap32.md#packageversion
1848+
[propertydeclaration-3]: roaringbitmap32.md#packageversion
1849+
[propertydeclaration-4]: roaringbitmap32.md#size
1850+
[propertydeclaration-5]: roaringbitmap32.md#isempty

index.d.ts

+107-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,52 @@ import roaring = require('./')
2727
* @implements {Iterable<number>}
2828
* @author Salvatore Previti
2929
*/
30-
export class RoaringBitmap32 implements Iterable<number> {
30+
export class RoaringBitmap32 implements Set<number> {
3131
// Allows: import RoaringBitmap32 from 'roaring/RoaringBitmap32'
3232
private static readonly default: typeof RoaringBitmap32
3333

34+
/**
35+
* Property: The version of the CRoaring libary as a string.
36+
* Example: "0.4.0"
37+
*
38+
* @export
39+
* @constant
40+
* @type {string} The version of the CRoaring libary as a string. Example: "0.2.42"
41+
*/
42+
public static readonly CRoaringVersion: string
43+
44+
/**
45+
* Property: The version of the roaring npm package as a string.
46+
* Example: "1.2.0"
47+
*
48+
* @export
49+
* @constant
50+
* @type {string} The version of the roaring npm package as a string. Example: "0.2.42"
51+
*/
52+
public static readonly PackageVersion: string
53+
54+
/**
55+
* Property: The version of the CRoaring libary as a string.
56+
* Example: "0.4.0"
57+
*
58+
* @export
59+
* @constant
60+
* @type {string} The version of the CRoaring libary as a string. Example: "0.2.42"
61+
* @memberof RoaringBitmap32
62+
*/
63+
public readonly CRoaringVersion: string
64+
65+
/**
66+
* Property: The version of the roaring npm package as a string.
67+
* Example: "1.2.0"
68+
*
69+
* @export
70+
* @constant
71+
* @type {string} The version of the roaring npm package as a string. Example: "0.2.42"
72+
* @memberof RoaringBitmap32
73+
*/
74+
public readonly PackageVersion: string
75+
3476
/**
3577
* Property. Gets the number of items in the set (cardinality).
3678
*
@@ -336,7 +378,7 @@ export class RoaringBitmap32 implements Iterable<number> {
336378
public static xorMany(...values: RoaringBitmap32[]): RoaringBitmap32
337379

338380
/**
339-
* [Symbol.iterator]() Gets a new iterator able to iterate all values in the set in order.
381+
* [Symbol.iterator]() Gets a new iterator able to iterate all values in the set in ascending order.
340382
*
341383
* WARNING: Is not allowed to change the bitmap while iterating.
342384
* The iterator may throw exception if the bitmap is changed during the iteration.
@@ -347,7 +389,7 @@ export class RoaringBitmap32 implements Iterable<number> {
347389
public [Symbol.iterator](): RoaringBitmap32Iterator
348390

349391
/**
350-
* Gets a new iterator able to iterate all values in the set in order.
392+
* Gets a new iterator able to iterate all values in the set in ascending order.
351393
*
352394
* WARNING: Is not allowed to change the bitmap while iterating.
353395
* The iterator may throw exception if the bitmap is changed during the iteration.
@@ -359,6 +401,56 @@ export class RoaringBitmap32 implements Iterable<number> {
359401
*/
360402
public iterator(): RoaringBitmap32Iterator
361403

404+
/**
405+
* Gets a new iterator able to iterate all values in the set in ascending order.
406+
* This is just for compatibility with the Set<number> interface.
407+
*
408+
* WARNING: Is not allowed to change the bitmap while iterating. Undefined behaviour.
409+
* The iterator may throw exception if the bitmap is changed during the iteration.
410+
*
411+
* Same as [Symbol.iterator]()
412+
*
413+
* @returns {RoaringBitmap32Iterator} A new iterator
414+
* @memberof RoaringBitmap32
415+
*/
416+
public keys(): RoaringBitmap32Iterator
417+
418+
/**
419+
* Gets a new iterator able to iterate all values in the set in ascending order.
420+
* This is just for compatibility with the Set<number> interface.
421+
*
422+
* WARNING: Is not allowed to change the bitmap while iterating. Undefined behaviour.
423+
* The iterator may throw exception if the bitmap is changed during the iteration.
424+
*
425+
* Same as [Symbol.iterator]()
426+
*
427+
* @returns {RoaringBitmap32Iterator} A new iterator
428+
* @memberof RoaringBitmap32
429+
*/
430+
public values(): RoaringBitmap32Iterator
431+
432+
/**
433+
* Gets a new iterator able to iterate all value pairs [value, value] in the set in ascending order.
434+
* This is just for compatibility with the Set<number> interface.
435+
*
436+
* WARNING: Is not allowed to change the bitmap while iterating. Undefined behaviour.
437+
* The iterator may throw exception if the bitmap is changed during the iteration.
438+
*
439+
* Same as [Symbol.iterator]()
440+
*
441+
* @returns {RoaringBitmap32Iterator} A new iterator
442+
* @memberof RoaringBitmap32
443+
*/
444+
public entries(): IterableIterator<[number, number]>
445+
446+
/**
447+
* Executes a function for each value in the set, in ascending order.
448+
* The callback has 3 arguments, the value, the value and this (this set). This is to match the Set<number> interface.
449+
*
450+
* WARNING: Is not allowed to change the bitmap while iterating. Undefined behaviour.
451+
*/
452+
public forEach(callbackfn: (value: number, value2: number, set: this) => void, thisArg?: any): void
453+
362454
/**
363455
* Gets the minimum value in the set.
364456
*
@@ -862,6 +954,16 @@ export class RoaringBitmap32 implements Iterable<number> {
862954
*/
863955
public clone(): RoaringBitmap32
864956

957+
/**
958+
* Returns always "RoaringBitmap32".
959+
*
960+
* To have a standard string representation of the content as a string, call contentToString() instead.
961+
*
962+
* @returns {string} "RoaringBitmap32"
963+
* @memberof RoaringBitmap32
964+
*/
965+
readonly [Symbol.toStringTag]: string
966+
865967
/**
866968
* Returns always "RoaringBitmap32".
867969
*
@@ -1047,7 +1149,7 @@ export interface RoaringBitmap32Statistics {
10471149

10481150
/**
10491151
* Property: The version of the CRoaring libary as a string.
1050-
* Example: "0.2.42"
1152+
* Example: "0.4.0"
10511153
*
10521154
* @export
10531155
* @constant
@@ -1058,7 +1160,7 @@ export const CRoaringVersion: string
10581160

10591161
/**
10601162
* Property: The version of the roaring npm package as a string.
1061-
* Example: "0.2.2"
1163+
* Example: "1.2.0"
10621164
*
10631165
* @export
10641166
* @constant

0 commit comments

Comments
 (0)