Skip to content

Commit b77e895

Browse files
committed
Release v5.2
1 parent 5479968 commit b77e895

File tree

15 files changed

+3217
-1328
lines changed

15 files changed

+3217
-1328
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
.DS_Store
2+
node_modules

.travis.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Robert Eisele
3+
Copyright (c) 2025 Robert Eisele
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
# BitSet.js
22

3-
[![NPM Package](https://nodei.co/npm-dl/bitset.png?months=6&height=1)](https://npmjs.org/package/bitset)
4-
5-
[![Build Status](https://travis-ci.org/infusion/BitSet.js.svg)](https://travis-ci.org/infusion/BitSet.js)
3+
[![NPM Package](https://img.shields.io/npm/v/bitset.svg?style=flat)](https://npmjs.org/package/bitset "View this project on npm")
64
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
75

6+
87
BitSet.js is an infinite [Bit-Array](http://en.wikipedia.org/wiki/Bit_array) (aka bit vector, bit string, bit set) implementation in JavaScript. Infinite means that if you invert a bit vector, the leading ones get remembered. As far as I can tell, BitSet.js is the only library which has this feature. It is also heavily benchmarked against other implementations and is the most performant implementation to date.
98

10-
Examples
11-
===
9+
## Examples
10+
11+
###Basic usage
1212

13-
Basic usage
14-
---
1513
```javascript
1614
let bs = new BitSet;
1715
bs.set(128, 1); // Set bit at position 128
1816
console.log(bs.toString(16)); // Print out a hex dump with one bit set
1917
```
2018

21-
Flipping bits
22-
---
19+
###Flipping bits
20+
2321
```javascript
2422
let bs = new BitSet;
2523
bs
@@ -33,15 +31,15 @@ if (str === "111111111111111111111111111000000011111111111111111111111111111") {
3331
}
3432
```
3533

36-
Range Set
37-
---
34+
###Range Set
35+
3836
```javascript
3937
let bs = new BitSet;
4038
bs.setRange(10, 18, 1); // Set a 1 between 10 and 18, inclusive
4139
```
4240

43-
User permissions
44-
---
41+
###User permissions
42+
4543
If you want to store user permissions in your database and use BitSet for the bit twiddling, you can start with the following Linux-style snippet:
4644
```javascript
4745
let P_READ = 2; // Bit pos
@@ -58,8 +56,8 @@ let world = new BitSet(P_EXEC);
5856
console.log("0" + user.toString(8) + group.toString(8) + world.toString(8));
5957
```
6058

61-
Installation
62-
===
59+
##Installation
60+
6361

6462
```
6563
npm install bitset
@@ -69,17 +67,17 @@ or
6967
bower install bitset.js
7068
```
7169

72-
Using BitSet.js with the browser
73-
===
70+
##Using BitSet.js with the browser
71+
7472
```html
7573
<script src="bitset.js"></script>
7674
<script>
7775
console.log(BitSet("111"));
7876
</script>
7977
```
8078

81-
Using BitSet.js with require.js
82-
===
79+
##Using BitSet.js with require.js
80+
8381
```html
8482
<script src="require.js"></script>
8583
<script>
@@ -90,8 +88,8 @@ function(BitSet) {
9088
</script>
9189
```
9290

93-
Constructor
94-
===
91+
##Constructor
92+
9593
The default `BitSet` constructor accepts a single value of one the following types :
9694

9795
- String
@@ -108,118 +106,118 @@ The default `BitSet` constructor accepts a single value of one the following typ
108106
- A BitSet object, which get copied over
109107

110108

111-
Functions
112-
===
109+
##Functions
110+
113111

114112
The data type Mixed can be either a BitSet object, a String or an integer representing a native bitset with 31 bits.
115113

116114

117-
BitSet set(ndx[, value=1])
118-
---
115+
###BitSet set(ndx[, value=1])
116+
119117
Mutable; Sets value 0 or 1 to index `ndx` of the bitset
120118

121119
int get(ndx)
122120
---
123121
Gets the value at index ndx
124122

125-
BitSet setRange(from, to[, value=1])
126-
---
123+
###BitSet setRange(from, to[, value=1])
124+
127125
Mutable; Helper function for set, to set an entire range to a given value
128126

129-
BitSet clear([from[, to]])
130-
---
127+
###BitSet clear([from[, to]])
128+
131129
Mutable; Sets a portion of a given bitset to zero
132130

133131
- If no param is given, the whole bitset gets cleared
134132
- If one param is given, the bit at this index gets cleared
135133
- If two params are given, the range is cleared
136134

137-
BitSet slice([from[, to]])
138-
---
135+
###BitSet slice([from[, to]])
136+
139137
Immutable; Extracts a portion of a given bitset as a new bitset
140138

141139
- If no param is given, the bitset is getting cloned
142140
- If one param is given, the index is used as offset
143141
- If two params are given, the range is returned as new BitSet
144142

145-
BitSet flip([from[, to]])
146-
---
143+
###BitSet flip([from[, to]])
144+
147145
Mutable; Toggles a portion of a given bitset
148146

149147
- If no param is given, the bitset is inverted
150148
- If one param is given, the bit at the index is toggled
151149
- If two params are given, the bits in the given range are toggled
152150

153-
BitSet not()
154-
---
151+
###BitSet not()
152+
155153
Immutable; Calculates the bitwise complement
156154

157-
BitSet and(Mixed x)
158-
---
155+
###BitSet and(Mixed x)
156+
159157
Immutable; Calculates the bitwise intersection of two bitsets
160158

161-
BitSet or(Mixed x)
162-
---
159+
###BitSet or(Mixed x)
160+
163161
Immutable; Calculates the bitwise union of two bitsets
164162

165-
BitSet xor(Mixed x)
166-
---
163+
###BitSet xor(Mixed x)
164+
167165
Immutable; Calculates the bitwise xor between two bitsets
168166

169-
BitSet andNot(Mixed x)
170-
---
167+
###BitSet andNot(Mixed x)
168+
171169
Immutable; Calculates the bitwise difference of two bitsets (this is not the nand operation!)
172170

173-
BitSet clone()
174-
---
171+
###BitSet clone()
172+
175173
Immutable; Clones the actual object
176174

177-
Array toArray()
178-
---
175+
###Array toArray()
176+
179177
Returns an array with all indexes set in the bitset
180178

181-
String toString([base=2])
182-
---
179+
###String toString([base=2])
180+
183181
Returns a string representation with respect to the base
184182

185-
int cardinality()
186-
---
183+
###int cardinality()
184+
187185
Calculates the number of bits set
188186

189-
int msb()
190-
---
187+
###int msb()
188+
191189
Calculates the most significant bit (the left most)
192190

193-
int ntz()
194-
---
191+
###int ntz()
192+
195193
Calculates the number of trailing zeros (zeros on the right). If all digits are zero, `Infinity` is returned, since BitSet.js is an arbitrary large bit vector implementation.
196194

197-
int lsb()
198-
---
195+
###int lsb()
196+
199197
Calculates the least significant bit (the right most)
200198

201-
bool isEmpty()
202-
---
199+
###bool isEmpty()
200+
203201
Checks if the bitset has all bits set to zero
204202

205-
bool equals()
206-
---
203+
###bool equals()
204+
207205
Checks if two bitsets are the same
208206

209-
BitSet.fromBinaryString(str)
210-
---
207+
###BitSet.fromBinaryString(str)
208+
211209
Alternative constructor to pass with a binary string
212210

213-
BitSet.fromHexString(str)
214-
---
211+
###BitSet.fromHexString(str)
212+
215213
Alternative constructor to pass a hex string
216214

217-
BitSet.Random([n=32])
218-
---
215+
###BitSet.Random([n=32])
216+
219217
Create a random BitSet with a maximum length of n bits
220218

221-
Iterator Interface
222-
===
219+
##Iterator Interface
220+
223221
A `BitSet` object is iterable. The iterator gets all bits up to the most significant bit. If no bits are set, the iteration stops immediately.
224222

225223
```js
@@ -231,28 +229,29 @@ for (let b of bs) {
231229

232230
Note: If the bitset is inverted so that all leading bits are 1, the iterator must be stopped by the user!
233231

234-
Coding Style
235-
===
232+
233+
##Coding Style
234+
236235
As every library I publish, BitSet.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
237236

238-
Build the library
239-
===
240-
Gulp is optional for minifying with Google Closure Compiler. After cloning the Git repository, do:
237+
##Building the library
238+
239+
After cloning the Git repository run:
241240

242241
```
243242
npm install
244-
gulp
243+
npm run build
245244
```
246245

247-
Run a test
248-
===
246+
##Run a test
247+
249248
Testing the source against the shipped test suite is as easy as
250249

251250
```
252-
npm test
251+
npm run test
253252
```
254253

255-
Copyright and licensing
256-
===
257-
Copyright (c) 2014-2023, [Robert Eisele](https://raw.org/)
258-
Dual licensed under the MIT or GPL Version 2 licenses.
254+
## Copyright and licensing
255+
256+
Copyright (c) 2025, [Robert Eisele](https://raw.org/)
257+
Licensed under the MIT license.

0 commit comments

Comments
 (0)