xHarbour Reference Documentation > Function Reference |
Creates a new hash.
Hash( [<xKey1>, <xValue1> [, <xKeyN>, <xValueN>] ] ) --> hHash
The function returns a new hash, populated with the specified key/value pairs. If no parameter is passed, an empty hash is returned.
If the function is called with an odd number of arguments, or key values are specified which are not of data type Character, Date or Numeric, the return value is NIL.
Hash variables are usually initialized within a variable declaration using the literal Hash operator {=>}. The Hash() function is equivalent to this operator and allows for creating hashes programmatically outside a variable declaration.
Hashes can be populated with key/value pairs by passing an even number of parameters to the function. Data representing the key values must be of orderable data types which restricts them to the data types C, D and N.
See also: | {=>}, HAllocate(), HClone(), HCopy(), HGet(), HDel(), HEval(), HSet(), HSetCaseMatch(), HGetPartition() |
Category: | Hash functions , xHarbour extensions |
Source: | vm\hash.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example creates hashes using the literal hash operator // and the Hash() function. PROCEDURE Main LOCAL hHash1 := { "OPT1" => 10, "OPT2" => 20 } LOCAL hHash2, hHash3 hHash2 := Hash( "OPT2", 200, "OPT3", 300, "OPT4", 400 ) hHash3 := hHash1 + hHash2 ? ValToPrg( hHash3 ) // { "OPT1" => 10, "OPT2" => 200, "OPT3" => 300, "OPT4" => 400 } RETURN
http://www.xHarbour.com