Property

new StrFltMap()

String-Float hashmap.

Example

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

Methods

dat(n) → number

Returns n-th dat.

Example

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

Parameter

Name Type Optional Description

n

number

 

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

Returns

numberB The n-th data value.

get(key) → number

Returns dat given key.

Example

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

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

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

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

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

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.StrFltMap();
// add a key/dat pair
h.put('foo', 10.5);
// 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

stringB The n-th key.

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

Parameter

Name Type Optional Description

key

string

 

Hashmap key.

Returns

numberB n - Hashmap index number of the key.

load(fin) → module:ht.StrFltMap

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

Parameter

Name Type Optional Description

fin

module:fs.FIn

 

Input stream.

Returns

module:ht.StrFltMapB Self.

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

Add/update key-value pair.

Example

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

Parameters

Name Type Optional Description

key

string

 

Hashmap key.

data

number

 

Hashmap data.

Returns

module:ht.StrFltMapB 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.StrFltMap();
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.FOutB fout.

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

Sorts by dat.

Example

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

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

Sorts by keys.

Example

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