Language Reference Guide : 4. System Classes : IntegerHashTable Class : IntegerHashTable Examples
 
Share this page                  
IntegerHashTable Examples
In the following examples, an object of class IntegerHashTable is used to store customer objects based on the customer ID.
Set up the hash table with 100 buckets:
DECLARE
    cust_hash = IntegerHashTable;
ENDDECLARE
{
    cust_hash.Setup(size = 1000);
}
Retrieve customers from the database and insert them into the hash table:
DECLARE
    cust = Customer;
ENDDECLARE
{
    SELECT id AS :cust.id,
        name AS :cust.name,
        title AS :cust.title,
        address AS :cust.address
    FROM customer
    BEGIN
        cust_hash.InsertObject(key= cust.id , object=cust);
        cust = Customer.Create();
END;
    COMMIT;
}
Get customers from the hash table after entering the customer ID into the "id" field within a CompositeField "cust", which is mapped to a Customer object.
ON SETVALUE cust.id =
DECLARE
    cust = Customer DEFAULT NULL;
ENDDECLARE
{
    cust = Customer(cust_hash.Find(key=cust.id));
}
Copy all customer objects from the hash table into an ArrayObject:
DECLARE
    cust_arr = ARRAY OF Customer;
ENDDECLARE
{
    status = cust_hash.FindAll(results=cust_arr);
}
Remove a customer with a specified ID from the hash table:
status = cust_hash.RemoveObject(key=cust.id);
Remove all customer objects from the hash table:
cust_hash.Clear();