Associative array/Creation: Difference between revisions

Content added Content deleted
Line 1,359: Line 1,359:
Usually, in J, you would use a named pair of (same length) lists for this purpose - one of keys, one of values. There are a number of details here that vary with the the intended use patterns. (First you get it working and then if you run into bottlenecks you rebuild things to relieve the problems).
Usually, in J, you would use a named pair of (same length) lists for this purpose - one of keys, one of values. There are a number of details here that vary with the the intended use patterns. (First you get it working and then if you run into bottlenecks you rebuild things to relieve the problems).


That said, it's also possible to use the symbol table itself to hold the names. The symbol table has limitations (can only accept syntactically valid names), but we can turn arbitrary strings into valid symbols using base 62 encode and prefixing with a letter (hypothetically speaking, base 64 encode would let us build longer names than base 62, because of computational complexity issues - but the J symbol table also comes with a name length limit - 255 characters - and does not support 64 different characters in names):
However, it's also possible to use the symbol table itself to hold the names. The symbol table has limitations (can only accept syntactically valid names), but we can turn arbitrary strings into valid symbols using base 62 encode and prefixing with a letter (hypothetically speaking, base 64 encode would let us build longer names than base 62, because of computational complexity issues - but the J symbol table also comes with a name length limit - 255 characters - and does not support 64 different characters in names):


<lang J>coclass 'assocArray'
<lang J>coclass 'assocArray'