Property

new StrStrMap()

String-string hashmap.

Example

// create a new hashtable
ht = require('qminer').ht;
var h = new ht.StrStrMap();
// Adding two key/dat pairs
h.put('foo', 'bar');
h.put('dog', 'tisa');
// Getting data
h.hasKey('foo'); // returns true
h.get('dog'); // returns 'tisa'
h.key(1); // returns 'dog'
h.dat(1); // returns 'tisa'
h.length; // returns 2	
// Saving and loading:
var fs = require('qminer').fs;
fout = fs.openWrite('map.dat'); // open write stream
h.save(fout).close(); // save and close write stream
var h2 = new ht.StrStrMap(); // new empty table
var fin = fs.openRead('map.dat'); // open read stream
h2.load(fin); // load

Property

length

Number of key/dat pairs. Type number.

Example

// create a new hashtable
ht = require('qminer').ht;
var h = new ht.StrStrMap();
// Adding two key/dat pairs
h.put('foo', 'bar');
// get the number of key/dat pairs
var length = h.length; // returns 1

Methods

classDesc() → string

classDesc

Returns

string desc - Returns class description

dat(n) → string

Returns n-th dat.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');
// get the first dat
var key = h.key(0); // returns 'bar'

Parameter

Name Type Optional Description

n

number

 

Hashmap dat index number. Should be between 0 and length-1.

Returns

string The n-th data value.

get(key) → string

Returns dat given key.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');
// get the newly added data
var val = h.get('foo'); // returns 'bar'

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

string Hashmap data.

hasKey(key) → boolean

Returns true if the map has a given key.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');
// check if the hashtable has the key
h.hasKey('foo'); // returns true

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

boolean True if the map contains key. Otherwise, false.

key(key) → number

Returns the ID of the key provided as parameter.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');
// get key id of 'foo' 
var key = h.keyId('foo'); // returns 0

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

number n - Hashmap index number of the key.

key(n) → string

Returns n-th key.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');
// get the first key
var key = h.key(0); // returns 'foo'

Parameter

Name Type Optional Description

n

number

 

Hashmap key index number. Should be between 0 and length-1.

Returns

string The n-th key.

load(fin) → module:ht.StrStrMap

Loads the hashtable from input stream.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
var fs = qm.fs;
// create a new hashtable
var h = new ht.StrStrMap();
fout = fs.openWrite('map.dat'); // open write stream
h.save(fout).close(); // save and close write stream
var fin = fs.openRead('map.dat'); // open read stream
var h2 = new ht.StrStrMap();
h2.load(fin); // load

Parameter

Name Type Optional Description

fin

module:fs.FIn

 

Input stream.

Returns

module:ht.StrStrMap Self.

put(key, data) → module:ht.StrStrMap

Add/update key-value pair.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
// add a key/dat pair
h.put('foo', 'bar');

Parameters

Name Type Optional Description

key

string

 

Hashmap key.

data

string

 

Hashmap data.

Returns

module:ht.StrStrMap Self.

save(fout) → module:fs.FOut

Saves the hashtable to output stream.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
var fs = qm.fs;
// create a new hashtable
var h = new ht.StrStrMap();
fout = fs.openWrite('map.dat'); // open write stream
h.save(fout).close(); // save and close write stream

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

Output stream.

Returns

module:fs.FOut fout.

sortDat([asc]) → module:ht.StrStrMap

Sorts by dat.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
h.put('foo', 'bar');
h.put('dog', 'tisa');
// sort the hashtable by dat
h.sortDat();

Parameter

Name Type Optional Description

asc

boolean

Yes

If true, sorts in ascending order.

Defaults to true.

Returns

module:ht.StrStrMap Self.

sortKey([asc]) → module:ht.StrStrMap

Sorts by keys.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.StrStrMap();
h.put('foo', 'bar');
h.put('dog', 'tisa');
// sort the hashtable by keys
h.sortKey();

Parameter

Name Type Optional Description

asc

boolean

Yes

If true, sorts in ascending order.

Defaults to true.

Returns

module:ht.StrStrMap Self.