Javascript HashList

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Created page with "== Constructor == == Methods ==")
 
Line 1: Line 1:
 +
== General ==
 +
 +
This object holds properties distributed by the hash of the property name.<br>
 +
Hash is calculated using the internal Yate String hash algorithm.
 +
 +
 +
This object can be used when a script is holding a large number of values for fast retrieval (faster than the flat regular object properties list).
 +
 +
 +
Data can be stored and retrieved using the common javascript instructions:
 +
var hashList = new Engine.HashList;
 +
// Assign
 +
hashList.prop = 5;
 +
hashList.obj = {a:3};
 +
// Retrieve
 +
var tmp = hashList.prop;
 +
for (var tmp of hashList) {
 +
    // tmp contains values in hash list
 +
}
 +
for (var tmp in hashList) {
 +
    // tmp contains hash list key (property) name
 +
}
 +
// Delete
 +
delete hashList.prop;
 +
 
== Constructor ==
 
== Constructor ==
 +
 +
* '''new Engine.HashList([cnt])'''
 +
Parameters:<br/>
 +
'''cnt''' Numeric. Number of lists to distribute values. Clamped in interval [1..1024]. Default: 17<br/>
 +
 +
 +
For a proper distribution of values '''cnt''' should be a prime number.
 +
  
  
 
== Methods ==
 
== Methods ==
 +
 +
* '''count()'''
 +
Return:<br/>
 +
The number of elements in list.

Revision as of 15:58, 6 September 2024

General

This object holds properties distributed by the hash of the property name.
Hash is calculated using the internal Yate String hash algorithm.


This object can be used when a script is holding a large number of values for fast retrieval (faster than the flat regular object properties list).


Data can be stored and retrieved using the common javascript instructions:

var hashList = new Engine.HashList;
// Assign
hashList.prop = 5;
hashList.obj = {a:3};
// Retrieve
var tmp = hashList.prop;
for (var tmp of hashList) {
    // tmp contains values in hash list
}
for (var tmp in hashList) {
    // tmp contains hash list key (property) name
}
// Delete
delete hashList.prop;

Constructor

  • new Engine.HashList([cnt])

Parameters:
cnt Numeric. Number of lists to distribute values. Clamped in interval [1..1024]. Default: 17


For a proper distribution of values cnt should be a prime number.


Methods

  • count()

Return:
The number of elements in list.

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers