Hash function.

Content-Disposition: inline

It is possible create hash function from any Q object to long (8 byte integer)?

I want like this:
q1: (1; 2 3);
q2: (1; 2 3);
q3: (1j; 2 3);
q4: (`a; 2 3);
hf [q1;q2] / true
hf [q1;q3] / false
hf [q1;q4] / false

X-Mailer: Apple Mail (2.926)hf:~;~ is matchdoes this solve your problem?/b.yogaOn Sep 10, 2008, at 2:21 PM, Alexandr Batalshikov wrote:> It is possible create hash function from any Q object to long (8 > byte integer)?>> I want like this:> q1: (1; 2 3);> q2: (1; 2 3);> q3: (1j; 2 3);> q4: (`a; 2 3);> hf [q1;q2] / true> hf [q1;q3] / false> hf [q1;q4] / false>> >

I want to write function transformation for memoization like
http://jsoftware.com/help/dictionary/dmcapdot.htm

On Wed, Sep 10, 2008 at 4:33 PM, brain yoga <brainyoga@gmail.com> wrote:

hf:~;

~ is match

does this solve your problem?
/b.yoga

you can get the serialization (wire/file format) of any object w/-8!q)-8!10x010000000d000000fa01000000q)-8!()0x010000000e000000000000000000q)-8!(a:1 2)0x01000000270000006200630b000100000061000000010000000600020000000100000002000..this is a bytestring (type 4)you could presumably build whatever has you liked on top of itOn Wed, Sep 10, 2008 at 8:21 PM, Alexandr Batalshikov wrote:> It is possible create hash function from any Q object to long (8 byte> integer)?>> I want like this:> q1: (1; 2 3);> q2: (1; 2 3);> q3: (1j; 2 3);> q4: (`a; 2 3);> hf [q1;q2] / true> hf [q1;q3] / false> hf [q1;q4] / false>> >>– Aaron Daviesaaron.davies@gmail.com

Ok. Is good solution. Thanks you.


<1ebd940e0809100626l5ee5364bma388720db1de1ec1@mail.gmail.com>

you have to write the memoization code yourself

taking the Fibonacci example
q)f:{$[1>=x;1;f[x-1]+f x-2]}
q)f 32
3524578

q)M!:m:0#0;m:{$[not null c:M x;c;M:$[1>=x;1;m[x-1]+m x-2]]} /note
the global to store the memoized values
q)m 32
3524578

q)\t f 32
9387
q)\t m 32
0 /not too meaningful
q)\t do[100;M!:m:0#0;m 32]
17 /that is quite an advantage

q)M
0 | 1
1 | 1
2 | 2
3 | 3
4 | 5
5 | 8
6 | 13
7 | 21
8 | 34
9 | 55
10| 89
11| 144
12| 233
13| 377
14| 610
15| 987
16| 1597
17| 2584
18| 4181
19| 6765
20| 10946
21| 17711
..

you might consider making having the key a unique attribute `u#
(which creates/maintains a hash) if M will become large

Regards,
Attila

Thanks you.
I write similar code, but your sample is pretty.
“M!:m:0#0” is cool!

 To my regret, fibonacci in CPS style in Q (http://osdir.com/ml/lang.ocaml.beginners/2002-09/msg00000.html) should be not so pretty. ;)