A bag is a unique collection of values. You can add values to the bag and test if the value is in the bag.

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

TMP_Bag.inc

The first template included is TMP_Bag.inc. This file contains the template for generating a typed unique collection of items. 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_LongBag.param

This provides the parameters for creating a unique collection of Long's. The Specific include file it uses is LongSupport.inc, because TKEY = Long.

Generating:

PbReplace gen_LongBag.param

Tokens:

TKEY
The data type of each key in the collection, in this case Long.
CMP
A function that compares two Longs. It returns 0 if they are the same. This routine should be in LongSupport.inc. The value used is LongCmp.
HASH
A function that returns an index of where the item would go in the hash table. This routine should be in LongSupport.inc. The value used is LongHash.
KEYREF
Determines how keys are passed to routines. In this case since the keys are Longs, they are passed ByVal.

gen_StringBag.param

This provides the parameters for creating a unique collection of String's. The Specific include file it uses is StringSupport.inc, because TKEY = String.

Generating:

PbReplace gen_StringBag.param

Tokens:

TKEY
The data type of each key in the collection, in this case String.
CMP
A function that compares two Strings. It returns 0 if they are the same. This routine should be in StringSupport.inc. The value used is StrStrICmp, a case insenstive string comparison. As a result the collection will be a unqiue collection of string without regard to case.
HASH
A function that returns an index of where the item would go in the hash table. This routine should be in StringSupport.inc. The value used is StrIHash. This computes a case insensitive hash index.
KEYREF
Determines how keys are passed to routines. In this case since the keys are Strings, they are passed ByRef.