Javascript HashList
From Yate Documentation
(Difference between revisions)
(Created page with "== Constructor == == Methods ==") |
|||
| (One intermediate revision by one user not shown) | |||
| 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. | ||
| + | |||
| + | |||
| + | [[Category:Javascript]] | ||
Latest revision as of 12:38, 9 September 2024
[edit] 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;
[edit] 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.
[edit] Methods
- count()
Return:
The number of elements in list.