.NET provides several types of collections. Two of them, arrays and ArrayLists, are
built-in to Basic4PPC but their full functionality is not exposed. This library provides
an ArraysEx object that provides enhanced array handling for Basic4PPC and an
ArrayListsEx object that enhances theArrayList control. Four other collections, Stack,
Queue, Hashtable and SortedList, described below, are provided by this library. This
library will run on both desktop and device but requires .NET 2.0.
Introduction
Collections vary depending on how the elements are stored, how they are sorted, how
searches are performed, and how comparisons are made. The Queue collection
provides first-in-first-out lists, while the Stack collection provides last-in-first-out
lists. The SortedList collection provides sorted versions of the Hashtable collection.
The elements of a Hashtable are accessible only by the key of the element, but the
elements of a SortedList are accessible either by the key or by the index of the
element. The indexes in all collections are zero-based.
The Queue and Stack collections are useful when you need temporary storage for
information, that is, when you might want to discard an element after retrieving its
value. Use Queue if you need to access the information in the same order that it is
stored in the collection. Use Stack if you need to access the information in reverse
order.
Hashtable
A Hashtable consist of a set of key and value pair, which are always Basic4PPC
weakly typed variables, and provides access to a value by means of its' key. The
lookup of a key is optimised using a hash function and is much faster than a search -
even a binary search. A hash function is an algorithm that returns a numeric hash code
based on a key.
A Hashtable object consists of buckets that contain the key/value pairs of the
collection. A bucket is a virtual subgroup of elements within the Hashtable, which
makes searching and retrieving easier and faster than in most collections. Each bucket
is associated with a hash code based on the key of the element.
When a key/value pair is added to a Hashtable, it is stored in the bucket that is
associated with the hash code that matches the key's hash code. When a value is being
searched for in the Hashtable, the hash code is generated for that key, and the bucket
associated with that hash code is searched and the value returned.
Queue
Queues are useful for storing data in the order it was received, perhaps from external
sources, for sequential processing. A queue can be viewed as a circular array. Objects
stored in a Queue are inserted at one end and removed from the other. As well as
methods for the normal weakly typed Basic4PPC variables methods for strongly
typed variables are also provided. These are intended for use in conjunction with
strongly typed Basic4PPC arrays and with external libraries that might require such
types.
SortedList
A SortedList also consists of a set of key and value pairs which are always Basic4PPC
weakly typed variables. A SortedList element can be accessed by its key, like an
element in a Hashtable, or by its index, like an element in an ArrayList.
A SortedList internally maintains two arrays to store the elements of the list; that is,
one array for the keys and another array for the associated values. Each element is a
key/value pair. The elements of a SortedList are sorted by the keys . A SortedList
does not allow duplicate keys.
The index sequence is based on the sort sequence. When an element is added, it is
inserted into SortedList in the correct sort order, and the indexing adjusts accordingly.
When an element removed, the indexing also adjusts accordingly. Therefore, the
index of a specific key/value pair might change as elements are added or removed
from the SortedList.
Operations on a SortedList tend to be slower than operations on a Hashtable because
of the sorting. However, the SortedList offers more flexibility by allowing access to
the values either through the associated keys or through the indexes. Indexes are zero-based
Stack
Stacks provide last-in-first-out access to data. They are one of the most important
structures in computing used by compilers for language parsing, mathematical
operations and variable storage during sub-routine calls. They are less pervasive at the
software application level. As well as methods for the normal weakly typed
Basic4PPC variables methods for strongly typed variables are also provided. These
are intended for use in conjunction with strongly typed Basic4PPC arrays and with
external libraries that might require such types.