xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Hash()

Creates a new hash.

Syntax

Hash( [<xKey1>, <xValue1> [, <xKeyN>, <xValueN>] ] ) --> hHash

Arguments

<xKey1> .. <xKeyN>
<xKey1> is the key value associated with <xValue1> in the hash. The key value is usually of data type Character, but may be a Date or Numeric value.
<xValue1> .. <xValueN>
<xValue1> is a value in the hash which can be accessed through its key value <xKey1>.

Return

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.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe