Contains TLookupStringList, an unsorted StringList with a fast lookup feature.

lookupstringlist.pas contains TLookupStringList, an unsorted StringList with a fast lookup feature. This file is part of the LazUtils package.

Authors: Juha Manninen / Antônio Galvão

Implements an unsorted StringList with a fast lookup feature.

TLookupStringList is a TStringList descendant that implements an unsorted string list with a fast lookup feature. Internally it uses a map container to store the strings which are used in the Contains, IndexOf and Find methods. The map container does not reserve too much memory because the strings are reference counted and not copied.

All values for the Duplicates property are fully supported, including dupIgnore and dupError (unlike in unsorted TStringList class).

This class is useful when you must preserve the order in list, but also need to do fast lookups to see if a string exists, or must prevent duplicates.

Authors: Juha Manninen / Antônio Galvão

TStringList
Adds a new value to the items and the string map with duplicate enforcement.

InsertItem is an overridden method which ensures that the internal String map and the Duplicates property are used when an item value is inserted. When Sorted contains False, the value in Duplicates determines the actions taken.

dupAccept
  Duplicates are allowed. Inserts the item and adds it to the string map.
dupIgnore
  Ignores duplicates. No actions are performed when S is already in the string map.
dupError
  Raises an Exception if S is already in the string map.

InsertItem calls the inherited method, and adds the value in S to the internal string map.

Raises an Exception when adding a duplicated value and Duplicates contains dupError. Raised with the message 'TLookupStringList.InsertItem: Duplicates are not allowed.'

TStringList
Position for the new item.
Value for the new item.
Constructor for the class instance.

Create is the constructor for the class instance, and calls the inherited constructor. Create allocates the internal TStringMap instance used in the class.

TStrings.Create
Destructor for the class instance.

Destroy is the destructor for the class instance. Destroy frees the internal TStringMap instance allocated in the constructor, and calls the inherited Destroy method.

TStringList.Destroy
Implements object persistence in the class.

Assign is an overridden method which implements the object persistence mechanism in the class. Assign ensures that property values in Source are stored in the current class instance. Assign calls the inherited method. When Source is a TLookupStringList class instance, the values in its internal string map are also stored in the current class instance.

TStrings.Assign
Persistent object with property values for the class instance.
Clears the content stored in the class instance.

Clear is an overridden method used to clear the content stored in Strings, Objects, and the internal string map. Clear calls the inherited method, and calls the TStringMap.Clear method in the internal string map.

TStringList.Clear
Deletes the value at the specified position.

Delete is an overridden method which ensures that the internal string map is maintained when deleting the value stored at the specified position. The corresponding value in Strings is used to check for duplicates using IndexOf. When a duplicate exists, and Duplicates are not allowed, the value is also removed from the internal string map. Delete calls the inherited method to delete the values in Strings and Objects at the position in Index.

TStringList.Delete
Ordinal position of the value to delete.
Adds the specified value to the Strings in the list.

Add is an overridden Integer function used to enforce handling of Duplicates when adding the specified value to Strings. Add checks the values in Sorted and Duplicates to see if duplicates are allowed in the unsorted string list.

The return value is -1 if the value in S already exists in the string map, and no actions are performed in the method. Otherwise, the inherited Add method is called to store the value in S. The return value is the position in Strings where the new value was stored.

TStringList.Add
Ordinal position for the new value, or -1 when duplicates are not allowed.
Value to add to the Strings in the list.
Adds the specified values to the Strings and Objects in the list.

AddObject is an overridden Integer function used to add the specified values to the Strings and Objects in the list. AddObject calls the Add method to add the value in S to Strings.

The return value contains the ordinal position in Strings where the value was stored, or -1 when duplicate values are not allowed. If the return value is not -1, the Objects property is updated to include the value in AObject at the specified position.

TStrings.AddObject
Ordinal position for the new values, or -1 when duplicates are not allowed.
Value added to the Strings property.
Value added to the Objects property.
Determines if the specified value already exists in the string map.

Contains is a Boolean function used to determine if the specified value already exists in the internal string map for the string list. The return value is True when S is already stored in the TStringMap for the class.

Contains is called from the Add, InsertItem, and IndexOf methods.

True when the value is already stored in the TStringMap for the class.
Value to locate in the string map.
Locates the specified value in the Strings property.

Find is an overridden Boolean function used to locate the specified value in the Strings property. The value in Index contains the position in Strings where value was located using the IndexOf method. Index contains -1 if the value in S is not stored in Strings. The return value if True when Index contains a value other than -1.

Please note: Find does NOT call the inherited method.

TStringList.Find
True when the value is located in the Strings property.
Value to find in the Strings property.
Ordinal position where the value was found.
Gets the position in Strings where the specified value is stored.

IndexOf is an overridden Integer function used to get the position in Strings where the specified value is stored. IndexOf uses the internal String map to determine if the value in S is stored in the string list. If S already exists, the inherited method is called.

The return value contains the ordinal position for the specified value, or -1 when S does not exist in the string map.

TStringList.IndexOf
Ordinal position for the specified value, or -1 when it does not exist.
Value to locate in Strings.
Removes duplicate strings in the AStrings argument.

Removes duplicate strings (with case sensitivity) from AStrings. Deduplicate creates a TLookupStringList instance that is used to remove the duplicate values in AStrings.

TStrings instance examined in the function.
The number of duplicates removed from AStrings.