Hi Natural developers,
when teaching Natural in our shop to new colleagues, we did a more complex tutorial “implementing a hashmap”, to train not only basic syntax sugar but also advanced features like dynamic vars, aiv vars, copycode etc…
After some rework to simplify the interface, I would like to share our work with you.
feel free to get a copy here: [url]Google Code Archive - Long-term storage for Google Code Project Hosting.
to get additional informaton: [url]http://code.google.com/p/hmap-natural/[/url]
Introduction
Goal has been to provide basic routines, that implements a dynamic data structure using hash-algorithms to access data. As a rule of thump: the map becomes faster as an array as soon as it has more than 50 elements to be looked up (Windows).
It had been tested on zOS (NAT 4.2.6, NAT 4.2.7) and Windows (NAT 6.3), but should work for every platform.
Implementation features
dynamic datastructure
max-key-length (Byte): 4096
max-value-length (Byte): no limit
Basic-methods: INIT, INSERT, FIND
Additional-methods: REPORT, INFO, CLEAR
Basic Usage
initialize the map to store 10.000 values:
DEFINE DATA
LOCAL USING HMHMAPA0 /* hashmap: statistics variables, storage for hashitems
LOCAL USING HMINITA0 /* hashmap: init: max size
LOCAL USING HMITEMA0 /* hashmap: key-value-pair
LOCAL USING HMMSGERA /* hashmap: error-msg
END-DEFINE
RESET HMINITA0
HMINITA0.#HMAP-SIZE := 10000
CALLNAT 'HMINITN0' HMINITA0 HMHMAPA0 HMMSGERA
insert of a new value
HMITEMA0.#ITEM-KEY := '00000002'
HMITEMA0.#ITEM-DATA := '123'
CALLNAT 'HMINS-N0' HMHMAPA0 HMITEMA0 HMMSGERA
find a value
RESET HMINITA0
HMITEMA0.#ITEM-KEY := '00000002'
CALLNAT 'HMFINDN0' HMHMAPA0 HMITEMA0 HMMSGERA
WRITE '=' HMITEMA0.#ITEM-DATA