Property

new IntStrMap()

Int-string hashmap.

Example

// create a new hashtable
ht = require('qminer').ht;
var h = new ht.IntStrMap();
// Adding two key/dat pairs
h.put(10, 'foo');
h.put(20, 'bar');
// Getting data
h.hasKey(10); // returns true
h.get(20); // returns 'bar'
h.key(1); // returns 20
h.dat(1); // returns 'bar'
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.IntStrMap(); // 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.IntStrMap();
// Adding two key/dat pairs
h.put(10, 'foo');
// get the number of key/dat pairs
var length = h.length; // returns 1

Methods

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.IntStrMap();
// add a key/dat pair
h.put(10, 'foo');
// get the first dat
var key = h.key(0); // returns 'foo'

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.IntStrMap();
// add a key/dat pair
h.put(10, 'foo');
// get the newly added data
var val = h.get(10); // returns 'foo'

Parameter

Name Type Optional Description

key

number

 

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.IntStrMap();
// add a key/dat pair
h.put(10, 'foo');
// check if the hashtable has the key
h.hasKey(10); // returns true

Parameter

Name Type Optional Description

key

number

 

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.IntStrMap();
// add a key/dat pair
h.put(10, 'foo');
// get key id of 10 
var key = h.keyId(10); // returns 0

Parameter

Name Type Optional Description

key

number

 

Hashmap key.

Returns

number n - Hashmap index number of the key.

key(n) → number

Returns n-th key.

Example

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

Parameter

Name Type Optional Description

n

number

 

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

Returns

number The n-th key.

load(fin) → module:ht.IntStrMap

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.IntStrMap();
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.IntStrMap();
h2.load(fin); // load

Parameter

Name Type Optional Description

fin

module:fs.FIn

 

Input stream.

Returns

module:ht.IntStrMap Self.

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

Add/update key-value pair.

Example

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

Parameters

Name Type Optional Description

key

number

 

Hashmap key.

data

string

 

Hashmap data.

Returns

module:ht.IntStrMap 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.IntStrMap();
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.IntStrMap

Sorts by dat.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.IntStrMap();
h.put(10, 'foo');
h.put(20, 'bar');
// 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.IntStrMap Self.

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

Sorts by keys.

Example

// import modules
var qm = require('qminer');
var ht = qm.ht;
// create a new hashtable
var h = new ht.IntStrMap();
h.put(10, 'foo');
h.put(20, 'bar');
// 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.IntStrMap Self.