unique keys is a pretty important aspect of dictionaries.

It permits SET (or Alex's merge) functionality to determine whether it is an 
update or an append.  Where users appreciate this "auto-functionality".  
Without unique keys, the user must determine if they want update vs append, and 
if it is update "1 record" have a means to select (somehow) which of the 
duplicate keyed records they want to update.

without duplicate keys, this is an associative array.  ie 2 unrestricted 
regular J arrays.




On Tuesday, February 1, 2022, 10:19:50 a.m. EST, Henry Rich 
<henryhr...@gmail.com> wrote: 





This discussion is important.  I'd like to continue from this post.

To respond to Ian, who asked Who really needs this anyway?  I say that I 
got great use from C++ classes for ordered_map and unordered_map.  The 
operations can be done in J, but the speed advantage of hashing for 
lookups is so significant as to make the difference between tolerable 
and intolerable performance.

I would change the definition to:

A Dictionary is a collection of key/value pairs, where the keys and 
values can have any type and shape.  Keys are not necessarily unique.  
Keys and values may be given as unboxed but they will be boxed 
immediately before going into the Dictionary.

Supported operations:

Dic =: ~. Dic   discard kvs for duplicate keys
Dic =: Dic , k,v    add a KV
k { Dic  read value[s]
Dic =: v k} Dic  replace kv
k e. Dic   How many times does key exist?
{."1 Dic   list of all keys
{:"1 Dic  list of all values

?? delete key

Rob: what needs to be added to make the dictionary type as useful as it 
is in K?

Henry Rich
> To answer Henry's questions:
>
> My definition of a dictionary is:
> A collection where data is organized by key, where keys can be symbols,
> strings, or numbers (or possibly other data types) and values can be
> arbitrary J data.
>
> Essential dictionary operations are:
> - create/read/update/delete by key
> - query if key exists
> - enumerate all keys (returns an array of boxed keys)
> - enumerate all values (returns an array of boxed values)
> - merge two dictionaries e.g. (Z=: X merge Y) and if X and Y share any key,
> then Z gets the key/value pair from Y
>
> Nice features to have, but not necessary:
> - keys are stored in J's sorting order
> - dictionaries can be serialized/deserialized for persistent disk storage
> or for sending to other processes
>
>


-- 
This email has been checked for viruses by AVG.
https://www.avg.com


----------------------------------------------------------------------
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