That's nice, thanks.  Comments/questions below.

On 12/04/2017 02:42 PM, Raul Miller wrote:
If you're really going to use this one item at a time, you can greatly
increase average performance of deletes by deferring them for later
(for example). Similarly, you can avoid some overhead by implementing
that as an object.

That said, here's a more concise implementation:

emptyHash=: i.2 0
I didn't know you could define an array in which one dimension is 0, that's useful.
canonical=: boxopen
what's the point of this?  So you change the canonical form easily later?

hashSet=:1 :0
:
   j=. ({.y) i. x=. canonical x
I was afraid that since boxed are treated as atoms that it would be impossible to test for equality of their contents without unboxing them; I should have checked. :-[
   n=.-.o=. j<{:$y
   (({.y),n#x),:((o#m) (o#j)} {:y),n#m=. canonical m
)
So /that's/ the idiomatic way of dealing with simple conditionals, cool.

hashGet=:4 :0
   j=. ({.y) i. canonical x
   b=. +./j={:$y
   j { ({:y),b#<'not found'
)
And another trick for dealing with conditionals, nice.

Btw, what's the rationale for having  i. return #list in the case the element is not found?  Wouldn't it be easier if it returned _1, as many other languages do?

hashDel=:4 :0
   (-.({.y) e. canonical x) #"1 y
)
Why did you use e. here rather than =?
As you can see, I made a few changes to your interface.
Is it more J-like to have the collections on the right?
If you're not
going to support setting and selecting multiple values, you should
think about using variables instead.
I don't understand what you mean.  Use variables as opposed to a tacit definition?

On the other hand, if there's actual values to forming lists of these
things, leaving things boxed might make sense.
"these things"?

One thing that still bothers me: I would prefer to have the hash functions update the hash value rather than having to write

test =: 'ccc' (1,2,3) hashSet test

Is it possible to write a function that changes the value of one of its arguments?  Since J is a functional language that passes arguments by value rather than reference I'm guessing not.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to