Skip to content

Commit 536c615

Browse files
committed
docs(readme): initial readme
1 parent 2585552 commit 536c615

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[![npm version][npm-image]][npm-url]
2+
[![downloads][downloads-image]][npm-url]
3+
[![build status][build-image]][build-url]
4+
[![coverage status][coverage-image]][coverage-url]
5+
[![Language grade: JavaScript][lgtm-image]][lgtm-url]
6+
[![Node.JS version][node-version]][node-url]
7+
8+
9+
# rotated-array-set
10+
11+
`RotatedArraySet` is a class looking a bit like the built-in [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) but is a set of arrays of `T`, and treats rotated arrays as "same".
12+
13+
14+
# API
15+
16+
Construct a `RotatedArraySet`, optionally provide a *stringify* method, converting `T` to `string` (this is not necessary for primitive types).
17+
18+
19+
## Example
20+
21+
```ts
22+
import { RotatedArraySet } from 'rotated-array-set'
23+
24+
const tree = new RotatedArraySet< string >( );
25+
26+
tree.insert( [ 'a', 'b', 'c' ] );
27+
tree.insert( [ 'x', 'y' ] );
28+
tree.insert( [ 'c', 'a', 'b' ] ); // won't insert, already has this but rotated
29+
tree.insert( [ 'y', 'x' ] ); // won't insert, same reason
30+
31+
tree.has( [ 'b', 'c', 'a' ] ); // true
32+
tree.has( [ 'c', 'b', 'a' ] ); // false - this isn't *rotated*
33+
34+
tree.values( ); // [ [ 'a', 'b', 'c' ], [ 'x', 'y' ] ]
35+
```
36+
37+
Provide a custom stringifier:
38+
39+
```ts
40+
import { RotatedArraySet } from 'rotated-array-set'
41+
42+
const tree = new RotatedArraySet< User >( user => `${user.first} ${user.last}` );
43+
44+
tree.insert( [ user1, user2, user3 ] );
45+
tree.insert( [ user3, user1, user2 ] ); // won't insert, already has this but rotated
46+
47+
tree.has( [ user2, user3, user1 ] ); // true
48+
tree.has( [ user3, user2, user1 ] ); // false - not *rotated*
49+
50+
tree.values( ); // [ [ user1, user2, user3 ] ]
51+
```
52+
53+
54+
[npm-image]: https://img.shields.io/npm/v/rotated-array-set.svg
55+
[npm-url]: https://npmjs.org/package/rotated-array-set
56+
[downloads-image]: https://img.shields.io/npm/dm/rotated-array-set.svg
57+
[build-image]: https://img.shields.io/github/workflow/status/grantila/rotated-array-set/Master.svg
58+
[build-url]: https://github.com/grantila/rotated-array-set/actions?query=workflow%3AMaster
59+
[coverage-image]: https://coveralls.io/repos/github/grantila/rotated-array-set/badge.svg?branch=master
60+
[coverage-url]: https://coveralls.io/github/grantila/rotated-array-set?branch=master
61+
[lgtm-image]: https://img.shields.io/lgtm/grade/javascript/g/grantila/rotated-array-set.svg?logo=lgtm&logoWidth=18
62+
[lgtm-url]: https://lgtm.com/projects/g/grantila/rotated-array-set/context:javascript
63+
[node-version]: https://img.shields.io/node/v/rotated-array-set
64+
[node-url]: https://nodejs.org/en/

0 commit comments

Comments
 (0)