Working on an application with Erel's KeyValueStore, I had the need to store more than one value per key.
Of course, it is always possible to combine several values to one (create a type or combine to comma separated string) but then you get all of them, have to break the package and use the value you need.
The attached class is an extension of the KeyValueStore, enabling storing of many values of different types per one key, storing and retrieving each value alone or as an array of values.
for almost each method in KVS there are two methods here:
- for handling a single value - use the method ending with 1
- for handling an array of values - use the method ending with 2
The index added to the methods type 1 is the number of the value in the key-values line, starting with 0.
Also added GetKeyBySimpleValue which is missing in regular maps.
The demo holds, in addition to new demo methods, a commented part of the original demo of KVS (with addition of index).
Edit: ver 1.1 , improved GetKeyBySimpleValue.
Edit: Sometimes you'll want to store values that are related to two keys, like for example the statistics of a basketball player - you'll have name and statistics type as the keys.
Or, several velues per two keys - if you want to store several teams data- you'll have team and player as keys, array of values for all types of statistics.
So I added two more store classes- both with two keys, one with single value, the other with single or array of values.
The structure of these classes is the same as the previously published so there is no demo.
Of course, it is always possible to combine several values to one (create a type or combine to comma separated string) but then you get all of them, have to break the package and use the value you need.
The attached class is an extension of the KeyValueStore, enabling storing of many values of different types per one key, storing and retrieving each value alone or as an array of values.
for almost each method in KVS there are two methods here:
- for handling a single value - use the method ending with 1
- for handling an array of values - use the method ending with 2
The index added to the methods type 1 is the number of the value in the key-values line, starting with 0.
Also added GetKeyBySimpleValue which is missing in regular maps.
The demo holds, in addition to new demo methods, a commented part of the original demo of KVS (with addition of index).
Edit: ver 1.1 , improved GetKeyBySimpleValue.
Edit: Sometimes you'll want to store values that are related to two keys, like for example the statistics of a basketball player - you'll have name and statistics type as the keys.
Or, several velues per two keys - if you want to store several teams data- you'll have team and player as keys, array of values for all types of statistics.
So I added two more store classes- both with two keys, one with single value, the other with single or array of values.
The structure of these classes is the same as the previously published so there is no demo.
Attachments
Last edited: