Coder Social home page Coder Social logo

mauriciosantos / buckets-js Goto Github PK

View Code? Open in Web Editor NEW
1.2K 43.0 111.0 1.4 MB

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

License: MIT License

JavaScript 97.55% CSS 1.53% HTML 0.92%
javascript data-structures collections collection linked-list dictionary map multimap stack queue

buckets-js's Introduction

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.

buckets-js's People

Contributors

mauriciosantos avatar tgrohens avatar timgates42 avatar zbyte64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

buckets-js's Issues

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!

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().

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

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.

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?

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?

Balanced Tree

Hi,
Are there any plans to add balanced tree in future (AVL or Red Black?)
Thanks!

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 .

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

AMD Loading

It's easy enough to add a define() after pull but would be great to have in the base lib.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.