Packages |
Description |
|
Hash implementation using a class and optinal pre-processor directives.
Hashes, or Associative Arrays, use named (and unique) elements to locate a value:
Procedure Main()
local hList := {=>}
local i
hList=>Fred := "Astair"
hList=>Ginger := "Rogers"
? hList=>Ginger // -> "Rogers"
hList := {=>} // empty hash
// use class syntax:
USE CUSTORDER INDEX CUSTID
GO TOP
While !Eof()
i := iif( hList:isKey( CUSTORDER->CUSTNAME ),;
hList:fetch(CUSTORDER->CUSTNAME),;
0)
// note: creates element if it doesn't already exist!
hList:put( CUSTORDER->CUSTNAME, ;
i+CUSTORDER->PRICE )
Enddo
// now print totals:
for i := 1 to hList:count()
? hList:key(i) // key
?? Space(2)
?? '$'+TransForm( hList:index(i), '999,999.99' ) // value (could also use hList=>[i])
next // e.g. SuperCorp Conglomeration Inc. $127,245.95
return
|
|
|