npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bgraph

v1.1.1

Published

B-Graph. B-Tree that can perform ranged search.

Downloads

29

Readme

B-Graph

B-Graph. B-Tree that can perform ranged search.

B-Graph Image

👨‍🏫 Notice

From v.1.1.0, everything has become asynchronous and i've added mutex to protect data during any data change. I will consider adding semaphore if too many data reading cause problems.

const bgraph = new BGraph(5, compareKey);

// It has to be asynchronous
async compareKey(key1, key2)
{
  if(key1.length > key2.length) return 1;
  else if (key1.length < key2.length) return -1;
  else return 0;
}

We also support having a fuction to compare 2 keys for ordering data in bgraph.This will let you have power to build a flexible bgraph structure that can be used to store data

▶️ install

npm i bgraph

👩‍🎓 Example

Code :

const BGraph = require('./bgraph.js');

async function test()
{
    console.time("BGraph");
    const bgraph = new BGraph();
    await bgraph.insert("a", "a");
    await bgraph.insert("b", "b");
    await bgraph.insert("c", "c");
    await bgraph.insert("d", "d");
    await bgraph.insert("e", "e");
    await bgraph.insert("f", "f");
    await bgraph.delete("a");
    await bgraph.delete("f");
    await bgraph.insert("g", "g");
    let serializedGraph = await bgraph.serialize();
    await bgraph.insert("h", "h");
    await bgraph.insert("i", "i");
    await bgraph.insert("j", "j");
    await bgraph.insert("k", "k");
    await bgraph.insert("l", "l");
    await bgraph.insert("m", "m");
    await bgraph.insert("n", "n");
    await bgraph.insert("o", "o");
    await bgraph.delete("o");

    await bgraph.deserialize(serializedGraph);

    let size = bgraph.size;
    let start = bgraph.start;

    console.log(start);

    for (let i = 0; i < size; i++)
    {
        console.log(start.value);
        start = start.next;
    }

    console.log("Search: ", await bgraph.search("d"));

    let result = await bgraph.searchRange("b", 7);
    for (let data of result)
    {
        console.log("key: ", data.key, "value: ", data.value);
    }

    console.timeEnd("BGraph");
}

test();

Result :

<ref *2> {
  key: 'b',
  value: 'b',
  next: <ref *1> {
    key: 'c',
    value: 'c',
    next: { key: 'd', value: 'd', next: [Object], prev: [Circular *1] },
    prev: [Circular *2]
  },
  prev: undefined
}
b
c
d
e
g
Search:  d
key:  b value:  b
key:  c value:  c
key:  d value:  d
key:  e value:  e
key:  g value:  g
BGraph: 15.503ms

📖 Simple document

| function | search(key) | | - | - | | description | This function is for searching value of key that is stored in b-graph | | arg: key | string | | return | return value if it is found otherwise it will return undefined |

| function | searchRange(key, total, position) | | - | - | | description | This function is for getting list of data from where the key at. | | arg: key | string | | arg: total | number, number of data to grab | | arg: position | number, number to skip data | | return | return filled list when data exist, return empty list for when it couldn't find, otherwise return undefined such as for the case that root node does not exist or key isn't string type |

| function | searchRangeBackward(key, total, position) | | - | - | | description | This function is for getting list of data from where the key at. It adds data backward. | | arg: key | string | | arg: total | number, number of data to grab | | arg: position | number, number to skip data | | return | return filled list when data exist, return empty list for when it couldn't find, otherwise return undefined such as for the case that root node does not exist or key isn't string type |

| function | searchKeyContains(substring, total, position, lastKey) | | - | - | | description | This function is for finding list of data that its key contains substring. | | arg: substring | string | | arg: total | number, number of data to grab | | arg: position | number, number to skip data | | arg: lastKey | string, last key where it should start search from | | return | return list of data, if root node does not exist it will return undefined |

| function | searchValueContains(substring, total, position, lastKey) | | - | - | | description | This function is for finding list of data that its value contains substring. | | arg: substring | string | | arg: total | number, number of data to grab | | arg: position | number, number to skip data | | arg: lastKey | string, last key where it should start search from | | return | return list of data, if root node does not exist it will return undefined |

| function | insert(key, value) | | - | - | | description | This function inserts data into b-graph | | arg: key | string, name of value | | arg: value | anything but recommend the value that can be JSON.stringfy() | | return | false for failure of inserting data, true for success |

| function | update(key, value) | | - | - | | description | TThis function updates data into b-graph | | arg: key | string, name of value | | arg: value | new value. anything but recommend the value that can be JSON.stringfy() | | return | false for failure of updating data, true for success |

| function | delete(key) | | - | - | | description | This function deletes the key of data from b-graph | | arg: key | string, name of value | | return | false for failure of deleting data, true for success |

| function | getAllKeys() | | - | - | | description | This function returns a list of all keys | | return | returns list of key, it can be empty |

| function | getAllValues() | | - | - | | description | This function returns a list of all values | | return | returns list of value, it can be empty |

| function | getAll() | | - | - | | description | This function returns a list of all data | | return | returns list of data, it can be empty |

| function | serialize() | | - | - | | description | serialize b-graph to string. | | return | string, serialized b-graph |

| function | deserialize(string) | | - | - | | description | deserialize string b-graph data. | | arg: string | string, serialized b-graph |

| function | serializeToObj() | | - | - | | description | serialize b-graph to object. | | return | object, serialized b-graph object |

| function | deserializeFromObj(data) | | - | - | | description | deserialize object b-graph data. | | arg: data | object, serialized b-graph object |

💪 Sponsor

Github sponsor page

👨‍💻 Author

Victor Chanil Park

💯 License

MIT, See LICENSE.