
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
disjoint-set-ds
Advanced tools
A disjoint-set data structure stores a collection of disjoint (non-overlapping) sets. It provides operations for adding new sets, merging sets (replacing them by their union), and finding a representative member of a set. Disjoint-set data structures play a key role in Kruskal's algorithm for finding the minimum spanning tree of a graph.
For more information read: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
In contrast to other available implementations of the data structure, the data structure does not assume that the elements stored are 0, 1, 2, ... but the actual elements are provided to makeSet and are being stored. The elements can be of any type.
import { DisjointSet } from 'disjoint-set-ds';
var ds = new DisjointSet();
ds.makeSet('Alice');
ds.makeSet('Bob');
console.log(ds.find('Alice')); // Alice
console.log(ds.find('Bob')); // Bob
ds.union('Bob', 'Alice');
console.log(ds.find('Alice')); // Bob <---
console.log(ds.find('Bob')); // Bob
An auxiliary data structure DisjointSetArray
is also provided for the simple case that the stored elements are the numbers 0, 1, 2, ...
import { DisjointSetArray } from "disjoint-set-ds";
var ds = new DisjointSetArray(3);
console.log(ds.find(0)); // 0
console.log(ds.find(1)); // 1
console.log(ds.find(2)); // 2
ds.union(0, 2);
console.log(ds.find(0)); // 0
console.log(ds.find(1)); // 1
console.log(ds.find(2)); // 0 <---
FAQs
Implementation of Disjoint sets data structure.
We found that disjoint-set-ds demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.