OScript API/Built-in Package Index |
The built-in functions in the HashMap package allow you to manipulate the HashMap ( hash map ) data type. A HashMap is a map for associating arbitrary key/value pairs. A HashMap differs from a Record in that the keys are less expensive to add and remove, the keys can be data types other than Strings, and the keys are sorted by key comparison rather than by some fixed order. Unlike an Assoc, HashMap keys are treated as case sensitive.
Each HashMap has an "undefined value" that is returned when a nonexistent key is referenced. This "undefined value" is usually Undefined by default, but any other value may be used.
A HashMap is formally created with HashMap.CreateHashMap(), however OScript has a convenience feature in that this is automatically invoked when a HashMap is declared so that it can be used right away. This does not happen with a Record since, while HashMap is meant to be a tool for relating data in an OScript program, Record is meant to be a tool for accessing database table data.
Constant flag used in ToAssoc() to indicate that the first value is to be used in the case where the HashMap contains multiple keys differing only in case.
The constant type identifier for the HashMap data type.
Constant flag used in ToAssoc() to indicate that the last value is to be used in the case where the HashMap contains multiple keys differing only in case.
Allocates a new Bytes of the given size.
Returns a new HashMap.
Removes a key/value pair from a HashMap.
Converts a Record to a HashMap.
Returns true if the HashMap contains key.
Returns a List of all the values in a HashMap.
Returns a List of all the keys in a HashMap
Merges hashmap2 into hashmap1.
Converts a HashMap into an Assoc.
Converts a HashMap into a Record.
Returns and optionally sets the "undefined value" of a HashMap.
Constant flag used in ToAssoc() to indicate that the first value is to be used in the case where the HashMap contains multiple keys differing only in case.
The type number for the HashMap data type.
Constant flag used in ToAssoc() to indicate that the last value is to be used in the case where the HashMap contains multiple keys differing only in case.
Creates and returns a shallow copy of the specified source HashMap. This is necessary since HashMaps are passed by reference, meaning that simple assignment does not copy a HashMap as it does with an Integer. The copying process follows the same conventions used in function parameter passing. Thus the contents of the copy will contain copies of those values in the source which are passed by value, and and references to those values in the source which are passed by reference.
The HashMap to copy.
The new HashMap copy.
The following example illustrates this:
HashMap a, b, b2, c Dynamic key c.ok = TRUE a.( 2006 ) = c a.count = 1 b = HashMap.copy( a ) // copy b2 = b // assignment does not copy b2.a = "a" // modify the reference b.alert = "Stop!" // modify the copy itself b.count += 1 // modify copy value b.( 2006 ).ok = FALSE // modify copy reference. for key in HashMap.keys( b ) Echo( "a.", key, " = ", a.( key ) ) Echo( "b.", key, " = ", b.( key ) ) end a.a = ? b.a = a // b2 mod referenced b a.alert = ? b.alert = Stop! // copy mod local a.count = 1 b.count = 2 // value mod local a.2006 = A<1,?,'ok'=false> b.2006 = A<1,?,'ok'=false> // reference mod not local
Returns a new, empty HashMap whose "undefined value" will be Undefined or value if value is specified. The "undefined value" is the value returned by a HashMap when referenced by a key it does not contain.
The "undefined value" of the returned HashMap, which will be Undefined if this argument is not specified.
A new, empty HashMap.
Removes the specified key from the HashMap if that HashMap contains the key.
The HashMap to remove a key/value pair from.
The key for the key/value pair to remove.
The value removed, or the "undefined value" if the key was not found.
Creates and returns a new HashMap containing the field names and corresponding columns of the specified Record as its String keys and associated values. As with HashMap.Copy(), the new HashMap returned will be a shallow copy of the Record.
The Record from which a HashMap will be created.
A new HashMap, copied from the Record.
Returns true if the specified HashMap contains the specified key.
The HashMap whose key set is tested.
The key to test.
Returns a List of the keyed values in a.
The HashMap whose values are returned in a List.
A List of the keyed values in the HashMap.
Returns a List of the keys in a.
The HashMap whose keys are returned in a List.
A List of keys in the HashMap.
The two HashMaps are merged by copying the contents of hashmap2 into hashmap1. The copy process is the same as used for HashMap.Copy().
Destination HashMap for merge.
HashMap whose contents are copied into hashmap1.
If a key is common to both HashMaps, then the associated value in hashmap1 will be replaced by that in hashmap2, as shown by the following example:
HashMap a, b, c Dynamic key a.value = "a" a.count = 1 b.value = "b" b.ok = FALSE c = HashMap.Merge( a, b ) for key in HashMap.Keys( a ) Echo( "a.", key, " = ", a.( key ) ) end a.count = 1 // only in a before merge a.ok = false // only in b before merge a.value = b // in both before merge, b superceded.
Creates a new Assoc and returns it after copying the values of the given HashMap into it.
The HashMap to convert into a new Assoc.
Flag to determine how multiple HashMap key, differing only in case, is mapped to the Assoc. If this parameter does not exists then the default value, HashMap.LIFO, is used indicating that the last value is used. The other option is HashMap.FIFO indicating that the first value is used.
A new Assoc copied from the HashMap.
Creates a new Record and returns it after copying the values of the given HashMap into it, translating String keys and values into field names and column entries. The HashMap should only contain String keys. As with HashMap.Copy(), the new HashMap returned will be a shallow copy of the Record.
The HashMap to convert into a new Record.
A new Record copied from the HashMap.
Returns the "undefined value" for the specified HashMap. If value is specified than the "undefined value" for the HashMap will be changed to value (meaning value will be returned).
The HashMap whose "undefined value" is queried and optionally set.
The "undefined value" for the HashMap.
Copyright © 2023 OpenText Corporation. All rights reserved. |