A map is a collection of key and value pairs. Essential you can map keys to values, or retrieve a value based on a key. The keys must be unique. keys and values may be retrieved by key or index. You can test for the existance of a key.

The generated map class is suited for adding, testing, retrieving, clearing items from the map. It does not currently impelement delete, you will need to update the template if you need deletion.

TMP_Map.inc

The second template included is TMP_Map.inc. This file contains the template for generating a typed unique collection of keys and the values they map to. The template uses two include files. SharedSupport.inc computes a hash table size. {TKEY}Support.inc should contain two functions. 1) a hash function. Given a key and hash table size, it computes the index where the key should go. 2) a comparison function. The comparison function returns 0 if two key values are the same.

There are a couple example parameter files included.

gen_LongToLongMap.param

This provides the parameters for mapping a unique collection of Longs to another Long value. The specific include file used is LongSupport.inc.

Generating:

PbReplace gen_LongToLongMap.param

Tokens:

TKEY
The data type of each key in the collection. In this case Long.
KEYREF
Determines how keys are passed to routines. In this case since the keys are Longs, they are passed ByVal.
KEYCMP
A function that compares two Longs. It returns 0 if the long values are the same and non-zero if they are different. In this case it uses LongCmp.
HASH
A function that returns the index of where a key would go in the hash table. This routine is in LongSupport.inc. The value used is LongHash.
TDATA
The data type of each mapped value in the collection. In this case Long.
DATAREF
Determines how data values are passed to routines. In this case since the keys are Longs, they are passed ByVal.

gen_StringToiStringBagMap.param

This provides the parameters for mapping a unique collection of Strings to a unique collection of strings. The specific include file used is StringSupport.inc. Since TKEY = String.

Generating:

PbReplace gen_StringToiStringBagMap.param

Tokens:

TKEY
The data type of each key in the collection. In this case String.
KEYREF
Determines how keys are passed to routines. In this case since the keys are Strings, they are passed ByRef.
KEYCMP
A function that compares two Strings. It returns 0 if the String values are the same and non-zero if they are different. In this case it uses StrStrICmp. As a result the unique keys will be case insensitive.
HASH
A function that returns the index of where a key would go in the hash table. This routine is in StringSupport.inc. The value used is StrIHash, which computes a case insensitive hash index.
TDATA
The data type of each mapped value in the collection. In this case iStringBag.
DATAREF
Determines how data values are passed to routines. In this case since the keys are iStringBags, they are passed ByRef.