Skip to content

Instantly share code, notes, and snippets.

View jdgamble555's full-sized avatar

Jonathan Gamble jdgamble555

View GitHub Profile
// Use: var tree = new OST(); tree.select(4); tree.insert(key,value)
var OST = function () {
// Order statistic tree node
var Node = function (leftChild, key, value, rightChild, parent) {
return {
leftChild: (typeof leftChild === "undefined") ? null :
leftChild,
key: (typeof key === "undefined") ? null : key,
value: (typeof value === "undefined") ? null : value,
rightChild: (typeof rightChild === "undefined") ? null :
@devagrawal09
devagrawal09 / dev's store.ts
Last active January 31, 2023 19:12
Simple reactive store for state management
export type QueryStatus = "loading" | "error" | "success";
export type ReadonlyStore<T> = {
getState: () => T;
subscribe: (
listenerOrStore: ((state: T) => void) | Store<any>
) => () => void;
};
export type Store<T> = ReadonlyStore<T> & {
setState: (newStateOrReducer: T | ((state: T) => T)) => void;