pyxis
v1.1.1
Published
associative container
Downloads
1
Readme
pyxis.ts
An associative container for TypeScript
Associative: values are referenced by key and not by position.
Unique keys: each key in container is unique.
Ordered: all keys are kept in order.
Mapped: each entry associates a key to a mapped value.
empty
: test whether container is empty or not.clear
: empties containersize
: returns number of entries in container.locate(key)
: locates value of entry by key.insert(key, value)
: inserts a unique key into container in sorted order.remove(key)
: removes key and its associated value from the container.enum
: enumerate the keys in the container
Install:
npm install pyxis
Compile:
tsc file-name.ts --target es5
Run:
node file-name.js
import Container from './node_modules/pyxis/index'
// create new container
let container = new Container()
// insert key-value pairs into container
// key and value can be of any type
container.insert(1, "foo")
container.insert(2, "bar")
container.insert(3, "baz")
// enumerate each key in the container
container.enum().forEach(el => {
console.log(el.key, el.value)
/*
1 'foo'
2 'bar'
3 'baz'
*/
})
// find item in container with key of "3"
console.log(container.locate(3)) // baz
// get the size of the container
console.log(container.size()) // 3
// remove item from container with key of "1"
container.remove(1)
console.log(container.size()) // 2
// test if container is empty
if(!container.empty()) console.log('contains stuff') // contains stuff
// clear all contents of container
container.clear()
console.log(container.size()) // 0