The Linked Map service program is a map implementation backed up by a linked list.
The map stores key/value pairs. It cannot contain duplicate keys. Each key must have a value and maps to at most one value. Though the value can also be a data structure or a pointer (to a list or a map).
The following features are available in the linked map service program (in no particular order):
- Creating a linked map
- Adding key/value pairs
- Adding key/value pairs with typed values
- Replacing values
- Clear the map
- Check size of the map
- Get entry of the map
- Check if the list contains a key or value
- Iterate through the keys
The implemented map is a backed by linked list. Key values are stored as an entry in the list. The memory is allocated from a user created heap. As the memory is dynamically allocated it is necessary to use the dispose procedure after using the map for freeing up the allocated memory. If the memory is not freed with the dispose procedure it will be released with the ending of the activation group or job.
The code is written in RPG IV free format. It uses some C-functions for working with memory and strings and intensely uses pointers.
// creating a map map = lmap_create(); // check if the list is empty (it should be) if (lmap_isEmpty(map)); dsply 'Map is empty'; else; dsply 'Map is not empty'; endif; // add key/value pair lmap_add(map : %addr(key) : %size(key) : %addr(value) : %size(value)); // add typed value lmap_addInteger(map : %addr(key) : %size(key) : 358); // iterate through the entries of the map valueÜPtr = lmap_iterate(map); dow (valuePtr <> *null); value = %str(valuePtr); dsply value; valuePtr = lmap_iterate(map); enddo; // freeing the allocated memory lmap_dispose(map);
The examples section contains some examples of how to use the linked lmap.
For source and binary packages take a look at the download area.
API documentation Linked Map service program can be viewed at the ILEDocs Sourceforge.net project. The documentation is generated from the source code.