Hi Alex,

Is this a bug or is my understanding of how to use  enum? from the
documentation not correct.

I have a little project where I would like to use 'enum. I was using 'idx
before, but 'enum looks like a much better fit. My current  problem is that
in a sparse array I am getting false positives as to whether a node exists
when checking with enum?

How do I use 'enum? to check for entry existence? Using the (val (enum
..)) and checking for NIL  also modifies the tree does it not. It is also
much slower than just 'enum?

Regards,
/Lindsay

# (====)

# Generate a 'Hash' value (based on Lehmer pseudo-random algo

(de Hasher (Val Seed)
   (default Seed 7337)
   (let (State Seed  Lst (if (lst? Val) Val (list Val)))
      (for C Lst
         (setq State (% (* (* C State) 279470273) 4294967291)) ) ) )

# Generate some hash values
(de TestEnum (N)
   (off *HT)
   (for I N
      (let (Val (Hasher I))
         (if (enum? '*HT Val)
            (prinl "! Duplicate: " I "; " Val "; " (enum? '*HT Val))
            (set (enum '*HT Val) I)
            (prinl "+ Added: " I "; " Val "; " (enum? '*HT Val)) ) ) ) )
# (====)

# Why does enum? report 'duplicate' hash value

: (TestEnum (** 2 3))
+ Added: 1; 1773995194;
! Duplicate: 2; 3547990388; 1
+ Added: 3; 1027018291;
+ Added: 4; 2801013485;
+ Added: 5; 280041388;
! Duplicate: 6; 2054036582; 3
+ Added: 7; 3828031776;
+ Added: 8; 1307059679;
-> NIL

# The hash values are all unique

: (for C (** 2 3) (printsp C (Hasher C)) (prinl) )
1 1773995194
2 3547990388
3 1027018291
4 2801013485
5 280041388
6 2054036582
7 3828031776
8 1307059679
-> NIL

# 'enum shows TestEnum didn't add the value, but also creates it doesn't it?

: (for C (** 2 3) (println (val (enum '*HT (Hasher C)))))
1
NIL
3
4
5
NIL
7
8
-> 8


P.S. For the integers between 1 and (2 ** 20) (the extent of my testing so
far) the Hasher functions generates unique values that are nicely
distributed and work well in an 'idx tree. As 'enum seems much faster (and
simpler) than 'idx,   I would like to use that, with an 'assoc list in the
value for any potential collisions. Note: the hasher currently handles
lists of numbers as well.

Reply via email to