ground:dictionary

v0.2.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

ground:dictionary Build Status

This is a small package that adds scope Dictionary

  • add(value) Adds a word to the dictionary returns index
  • addList(listArray) Adds an array of words to the dictionary
  • set(list) Sets the dictionary to a list of words
  • withoutInitial Returns list of words except those added at creation eg. var d = new Dictionary('foo', 'bar'); foo+bar will not be returned
  • value(index) get value at index
  • index(value) get index for value
  • exists(value) returns true if value exists in dictionary
  • clone clones the list and returns the list of words
  • toArray returns the list of words in the dictionary
  • toObject returns the word lookup object

Usage

In short:

1  var d = new Dictionary('foo', 'bar');
2  d.add('hello');
3  d.withoutInitial(); // returns ['hello']
4  d.value(0); // return 'foo'
5  d.index('bar'); // return 1
6  d.exists('foo'); // return true
7  d.exists('FOO');  // return false
8  d.clone(); // return cloned word list ['foo', 'bar', 'hello']
9  d.toArray(); // return the word list ['foo', 'bar', 'hello']
10  d.toObject(); // return { 'foo': 0, 'bar': 1, 'hello': 2 }

Where is this used?

This is part of the MiniMax package where MiniMax uses a dictionary to compress data.