A complete, fully tested and documented data structure library written in pure JavaScript.

Overview

Buckets

Build Status NPM Version

A JavaScript Data Structure Library

Buckets is a complete, fully tested and documented data structure library written in pure JavaScript.

Included data structures

Buckets also includes several functions for manipulating arrays.

Supported platforms

  • Every desktop and mobile browser (including IE6)
  • Node.js

If it supports JavaScript, it probably supports buckets.

Downloading Buckets

Download directly

Then, add it as a script tag to your page:

<script src="buckets.js"></script>
<script>
  var aSet = new buckets.Set();
</script>

Or install bucketsjs using bower

bower install bucketsjs

Or use an AMD loader

require(["./bower/bucketsjs/buckets.js"], function(buckets) {
  var hm = new buckets.Dictionary();
});

Or install buckets-js using npm

npm install buckets-js

In Node.js: var buckets = require('buckets-js');.

Usage

var a = new buckets.Set();
var b = new buckets.Set();
a.add(1);
a.add(2);
b.add(2);
a.union(b); // {1,2}

Read the documentation.

Building Buckets

There's nothing else you need to use buckets. However, this guide may help you if you wish to contribute to the project or modify it.

Comments
  • Adds a MultiBag data structure

    Adds a MultiBag data structure

    That's a data structure that I needed in a project I'm working on. I couldn't think of a way to use another structure from the existing ones, so I created this. I know that there aren't any tests or documentation strings. I'll write some if you think that this is a data structure that needs to be with the original buckets :)

    opened by nvlbg 5
  • performance question

    performance question

    Hello this is more of a question rather than an issue. I understand the theory behind these data structures, but i run a little test in action and i didn't really understand the results. I used a simple array from [0...10000] and the same as btree. I used underscore to give me the min,max and if array contains 9999, so it's the worst situation for array because it will do O(n) for these actions. So benchmarking that, btree is really good 2x faster than underscore functions. But in overall btree is like 10x slower than underscore functions. I believe this has to do with constructing the btree versus constructing a simple array? Is this expected? And if so, what is the point of using structures in javascript?

    opened by noemission 3
  • Does LinkedList expose the head node directly?

    Does LinkedList expose the head node directly?

    All of the methods I see in the documentation return the element from the underlying array. This makes it impossible to do something like node.next to walk the linked list. I looked at the source for a minute, am I missing something?

    opened by mikehaas763 2
  • npm published package

    npm published package

    It would be great if buckets was published as an NPM package to allow standard node/npm package management to track the latest release of buckets. I'd do it, but your name should be on it!

    opened by shanewholloway 2
  • fix missing check for undefined in multidictionary and add test

    fix missing check for undefined in multidictionary and add test

    Hi Mauricio,

    I found a bug in the remove function in multidictionary.js. The description states that if a key is missing, remove should return false. It actually doesn't make that check, and so calls buckets.remove on an undefined array, which raises an error.

    I added a test that triggers this behavior, as well as a possible fix, in the pull request.

    Cheers, Théotime

    opened by tgrohens 1
  • feature Bag1 <= Bag2

    feature Bag1 <= Bag2

    Hello,

    is there an easy way to test for inclusion of a Bag inside another Bag with buckets ? By inclusion I mean nCopies <= nCopies for each keys ?

    Thanks

    opened by jeromew 1
  • Various Dictionary bugs

    Various Dictionary bugs

    var dict = new buckets.Dictionary();
    
    dict.set("toString", 42);
    dict.size() === 0; // wrong, should be 1
    dict.remove("toString");
    dict.size() === -1; // wrong, should be 0
    
    dict.set("hasOwnProperty", "foo");
    try {
        dict.keys(); // throws an error trying to invoke "foo" as a function
    } catch(e) {
        dict.remove("hasOwnProperty");
    }
    
    dict.set("__proto__", {value: 123});
    dict.get("value") === 123; // wrong, should be undefined
    

    The __proto__ issue can be prevented by prefixing all keys with a weird character like "~" before storing them into table. this.table["~" + key] = {.....}

    Instead of this.table.hasOwnProperty, do:

    var has = function(obj, key) {
        Object.prototype.hasOwnProperty.call(obj, key);
    }
    has(table, key); // instead of table.hasOwnProperty(key)
    

    When checking whether or not the dictionary has a certain key, always use has().

    opened by cspotcode 1
  • Make this work as a NodeJS module

    Make this work as a NodeJS module

    The code added at the bottom of buckets.js will enable it to be used as a module in NodeJS. The if statement ensures the rest of the export code will be completely ignore if run in the browser.

    opened by tcoulter 1
  • added inorder using node

    added inorder using node

    i modified inorderTraverse by changing signature of function to inorderTraverse(callbacks, element = undefined) so that old functions would still work.

    opened by parhamsaremi 0
  • BSTree isn't balancing?

    BSTree isn't balancing?

    e.g. red-black tree or splay tree, c.f. npm bbtree

    If you insert into a non-balancing binary search tree from a sorted array, that can happen easily, the lookup performance breaks down to linear, the tree will look like

                o
                 \
                  o
                   \
                    o
                     \
                      o
                       \
                        . . .
    
    opened by cmonacaps 0
  • Removing the last element from a LinkedList is unnecessarily slow

    Removing the last element from a LinkedList is unnecessarily slow

    Removing the first element from a LinkedList is fast, however, removing the last element is slow.

    The problem seems to be that in the removeElementAtIndex function rather than simply accessing the lastNode element, the nodeAtIndex is called, fetching the second to last element, which is done by iterating over the entire list.

    Removing the last element from a LinkedList is very common, so it being crippled severely hampers the usability of the data structure.

    Thanks

    opened by tom-churchill 2
  • BSTree - inorderTraversal from specific starting point

    BSTree - inorderTraversal from specific starting point

    Hi, this library is awesome thanks for the work you put into it.

    We’re using BSTree to index domain names from documents. We can use inorderTraversal to traverse documents by our custom domain ranking.

    Is there a way to inorderTraverse from a specific starting point? (vs. traversing the whole tree). It seems like some other trees provide this and maybe it could be fairly straightforward to implement in BSTree.

    Use case: we want to get all docs for a certain domain (I.e. trello.com) without traversing the entire tree.

    opened by aguynamedben 2
  • methods created when creating new object should be in prototype chain not in object itself

    methods created when creating new object should be in prototype chain not in object itself

    methods created when creating new object should be in prototype chain not in object itself.

    Since functions/method itself an object , it memory for it , when creating a object.

    var que = new buckets.Queue();

    que object is created , and method like enqueue and dequeue is also created in object itself , not in prototype chain.

    If I create a hundreds of object like this. It will take a lot of memory .

    opened by sk16 4
Releases(v1.98.2)
Owner
Mauricio
Software Development Engineer at Amazon. Interested in distributed and cloud computing.
Mauricio
Immutable persistent data collections for Javascript which increase efficiency and simplicity.

Immutable collections for JavaScript Immutable data cannot be changed once created, leading to much simpler application development, no defensive copy

Immutable.js 32.4k Dec 31, 2022
ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript

mori A simple bridge to ClojureScript's persistent data structures and supporting APIs for vanilla JavaScript. Pull requests welcome. Breaking changes

David Nolen 3.4k Dec 31, 2022
Immutable persistent data collections for Javascript which increase efficiency and simplicity.

Immutable collections for JavaScript Immutable data cannot be changed once created, leading to much simpler application development, no defensive copy

Immutable.js 32.4k Jan 7, 2023
A simulation data generator

Mock.js Mock.js is a simulation data generator to help the front-end to develop and prototype separate from the back-end progress and reduce some mono

高云 墨智 18.7k Jan 4, 2023
mutate a copy of data without changing the original source

immutability-helper Mutate a copy of data without changing the original source Setup via NPM npm install immutability-helper --save This is a drop-in

Moshe Kolodny 5.1k Dec 29, 2022
JSON-Schema + fake data generators

Use JSON Schema along with fake generators to provide consistent and meaningful fake data for your system. What's next? Breaking-changes towards v0.5.

JSON Schema Faker 2.9k Jan 4, 2023
HashMap JavaScript class for Node.js and the browser. The keys can be anything and won't be stringified

HashMap Class for JavaScript Installation Using npm: $ npm install hashmap Using bower: $ bower install hashmap You can download the last stable ver

Ariel Flesler 381 Sep 24, 2022
A tiny JavaScript utility to access deep properties using a path (for Node and the Browser)

object-path Access deep properties using a path Changelog 0.11.5 SECURITY FIX. Fix a prototype pollution vulnerability in the set() function when usin

Mario Casciaro 1k Dec 29, 2022
An isomorphic and configurable javascript utility for objects deep cloning that supports circular references.

omniclone An isomorphic and configurable javascript function for object deep cloning. omniclone(source [, config, [, visitor]]); Example: const obj =

Andrea Simone Costa 184 May 5, 2022
Hjson for JavaScript

hjson-js Hjson, a user interface for JSON JSON is easy for humans to read and write... in theory. In practice JSON gives us plenty of opportunities to

Hjson 387 Dec 20, 2022
Data structures & algorithms implementations and coding problem solutions. Written in Typescript and tested with Jest. Coding problems are pulled from LeetCode and Daily Coding Problem.

technical-interview-prep Data structures & algorithms implementations and coding problem solutions. Written in Typescript and tested with Jest. Coding

Lesley Chang 7 Aug 5, 2022
Harrison Njuguna 5 Nov 11, 2022
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested

// ) ) ___ ___ ___ __//__ // ) ) // ) ) (( ) ) // // / / // //___/ / \ \ // ((___/ / ((___

Dmitri Zaitsev 64 Nov 20, 2022
A complete and heavily tested wrapper with typings for the zapper.fi API.

Zapperfi API Unofficial wrapper for the Zapperfi API Don't forget to leave a ⭐ if you found this useful. Install # use npm $ npm i zapperfi-api # use

izayl 6 Sep 4, 2022
A well documented set of tools for building node web applications.

Perk Framework Perk is a well documented set of tools for building node web applications. The goal of Perk is first and foremost to provide a well doc

Aaron Larner 179 Oct 26, 2022
Verbosely Documented, Minimal Starknet Contract Examples.

cairo-by-example • Verbosely Documented, Minimal Starknet Contract Examples. Cairo By Example deployed to https://cairo-by-example.xyz Developing Clon

andreas 63 Dec 6, 2022
A javascript standard data structure library which benchmark against C++ STL.

js-sdsl A javascript standard data structure library which benchmark against C++ STL. Note Note that our official version starts from 2.0.0. In order

Zilong Yao 5 Dec 10, 2022
This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configured and ready to use in real world projects!

Nuxt 3 Starter This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configure

Ali Soueidan 26 Dec 27, 2022
geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.

geotiff.js Read (geospatial) metadata and raw array data from a wide variety of different (Geo)TIFF files types. Features Currently available function

geotiff.js 649 Dec 21, 2022