Socket
Book a DemoInstallSign in
Socket

rotated-array-set

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rotated-array-set

Set of (possibly rotated) arrays

3.0.0
latest
Source
npmnpm
Version published
Weekly downloads
38K
0.61%
Maintainers
1
Weekly downloads
 
Created
Source

npm version downloads build status coverage status Node.JS version

rotated-array-set

RotatedArraySet is a class looking a bit like the built-in Set but is a set of arrays of T, and treats rotated arrays as "same".

API

Construct a RotatedArraySet, optionally provide a stringify method, converting T to string (this is not necessary for primitive types).

Versions

  • Since v2 this is a pure ESM package, and requires Node.js >=12.20. It cannot be used from CommonJS.
  • Since v3 requires Node.js >= 14.13.1.

Example

import { RotatedArraySet } from 'rotated-array-set'

const tree = new RotatedArraySet< string >( );

tree.insert( [ 'a', 'b', 'c' ] );
tree.insert( [ 'x', 'y' ] );
tree.insert( [ 'c', 'a', 'b' ] ); // won't insert, already has this but rotated
tree.insert( [ 'y', 'x' ] ); // won't insert, same reason

tree.has( [ 'b', 'c', 'a' ] ); // true
tree.has( [ 'c', 'b', 'a' ] ); // false - this isn't *rotated*

tree.values( ); // [ [ 'a', 'b', 'c' ], [ 'x', 'y' ] ]

Provide a custom stringifier:

import { RotatedArraySet } from 'rotated-array-set'

const tree = new RotatedArraySet< User >( user => `${user.first} ${user.last}` );

tree.insert( [ user1, user2, user3 ] );
tree.insert( [ user3, user1, user2 ] ); // won't insert, already has this but rotated

tree.has( [ user2, user3, user1 ] ); // true
tree.has( [ user3, user2, user1 ] ); // false - not *rotated*

tree.values( ); // [ [ user1, user2, user3 ] ]

Keywords

set

FAQs

Package last updated on 02 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.