Giter VIP home page Giter VIP logo

ts-skiplist's Introduction

Probablistic Skip List

Probably my favorite data structure. O(log n)

Implementation in TypeScript

Feel free to read up on them if you are interested.

This lib includes a basic implementation with a few exposed methods. The skip list is genericized for whatever data you are trying to store/lookup.

import { SkipList } from 'ts-skiplist';
const numSkipList = new SkipList<number>(maxLevel: number);
const strSkipList = new skipList<string>(maxLevel);

maxLevel is determined by you, the user. In this implementation, p = 0.5, so for example, using a maxLevel of 16 is sufficient for a list containing up to 2^16 values.

Skip List Methods

insert -> void

numSkipList.insert(4);
numSkipList.insert(6);

strSkipList.insert('apple');
strSkipList.insert('banana');

remove -> void

If the value being removed is not in the list, nothing happens

numSkipList.remove(4);
numSkipList.remove(6);

strSkipList.remove('apple');
strSkipList.remove('banana');

find -> Node<T> | undefined

const num = numSkipList.find(4);
const seven = numSkipList.find(7); // undefined because it is not found in the list

const str = strSkipList.find('apple');

Node<T>

The node contains the data value in the value attribute. Along with the counter and pointers fields should they need to be utilized. Additionally, there is an exposed increment() method that will increment the counter field by 1 (++).

public value: T;
public counter: number;
public pointers: Node<T>[];
public increment(): void {
    this.counter++;
}

ts-skiplist's People

Contributors

ksibod avatar

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.