Its an excellent exercise to design your own.  The recommended J way, is to 
imply a dictionary structure within your problem domain without actually using 
a formal dictionary process.

Some considerations when creating your own:

symbols as keys.  When you don't need to match on parts of strings, symbols are 
essentially integers "under the hood".  An array of symbols doesn't have the 
problem that strings do of adding fill spaces.

The above implies an inverted table format (search wiki)  an array of symbols 
as a single box for keys, and an array of values (boxed items if they are 
heterogeneous types, unboxed if they are compatible types).  Boxed is advised 
for the general case.

consider a functional approach instead of class.  the upsert function of a 
dictionary allows both setting (if key present) or inserting/appending (if not 
present).  If following the above guidelines, the dictionary itself is 2 boxes. 
 One for keys the other for values.  upsert can effectively merge the new (2 
box key/value pairs) into an existing 2 boxes of the same structure.   A monad 
version, just calls the dyad with a default empty 2 boxes.








________________________________
From: Herbert Weissenbaeck // Privat <h...@herbertweissenbaeck.com>
To: programm...@jsoftware.com 
Sent: Wednesday, April 12, 2017 8:34 AM
Subject: [Jprogramming] Dictionary with Strings as Keys



Next beginner's question: What would be an efficient/fast (or the recommended) 
J way to implement a dictionary with strings as keys and arbitrary contents 
(nouns, verbs, boxes) as values, which allows inserting, removing, fetching and 
editing?


Thank you.





Sent from my iPhone

----------------------------------------------------------------------

For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to