hash code for object ?
[1/7] from: arngar::gmail::com at: 6-Jun-2007 14:13
Hello,
Is there something like an hashcode for object in rebol as we have in
java ?
thanks
arnaud
[2/7] from: gregg:pointillistic at: 6-Jun-2007 9:40
Hi Arnaud,
AG> Is there something like an hashcode for object in rebol as we have
AG> in java ?
Yes, REBOL has a hash! datatype, which has the same interface as a
block!, but is (obviously) much faster for lookups. The only catch is
that the behavior is *slightly* different than the block! type for
some operations, so it's not a complete drop-in replacement in all
cases, depending on how you use it.
-- Gregg
[3/7] from: gregg:pointillistic at: 6-Jun-2007 9:44
Hi Arnaud,
AG> Is there something like an hashcode for object in rebol as we have in
AG> java ?
Forgot to include an example of how to make hash! values. You either
need to to MAKE, TO, or the serialized format:
>> make hash! [1 2 3 4 5]
== make hash! [1 2 3 4 5]
>> to hash! [1 2 3 4 5]
== make hash! [1 2 3 4 5]
There is also a list! type. Both hash! and list! are covered in the
Core manual in more detail as well.
-- Gregg
[4/7] from: tim-johnsons:web at: 6-Jun-2007 8:36
On Wednesday 06 June 2007, Gregg Irwin wrote:
> Hi Arnaud,
> AG> Is there something like an hashcode for object in rebol as we have in
<<quoted lines omitted: 7>>
> There is also a list! type. Both hash! and list! are covered in the
> Core manual in more detail as well.
Python has a dictionary type, which is sort of a hash implemented
as a btree.
One of the gotchas can be illustrated as follows:
>> H: make hash! [4 1 1 4]
== make hash! [4 1 1 4]
>> select H 1
== 1
;; if you think of 'H as a series of pairs, the python corollary would
;; return 4
;; The fix would be:
>> first select/skip H 1 2
== 4
;; which is easily implemented in a function such as:
mate: def["Finds an odd-numbered value in a series"
" and returns the value after it (the 'mate')"
[catch] b[series!] v[any-type!]][
res: select/skip b v 2
either block? res[first res][res]
]
;; Note my use of 'def and the multiple docstring :-)
tim
[5/7] from: tim-johnsons:web at: 6-Jun-2007 8:43
On Wednesday 06 June 2007, Tim Johnson wrote:
> ;; which is easily implemented in a function such as:
> mate: def["Finds an odd-numbered value in a series"
<<quoted lines omitted: 4>>
> ]
> ;; Note my use of 'def and the multiple docstring :-)
Oh, and one other thing, 'mate has not been tested on
a 'hash type.
[6/7] from: arngar:gmai:l at: 6-Jun-2007 19:15
Oops ! sorry I was not thinking about an hashmap, I mean an object
hash code:
http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#hashCode()
sorry if I was not clear ;-(
Le 6 juin 07 =E0 17:40, Gregg Irwin a =E9crit :
[7/7] from: gregg:pointillistic at: 6-Jun-2007 14:28
Hi Arnaud,
AG> Oops ! sorry I was not thinking about an hashmap, I mean an object
AG> hash code:
AG> http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#hashCode()
AG> sorry if I was not clear ;-(
Simple miscommunication on both sides. :) What you're probably after
is the CHECKSUM func. If you need to use it on an object, you'll need
to FORM or MOLD it first.
-- Gregg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted