hi guys,
i am curious if there is the concept of ‘set’ in q, or we just use a sorted list?
cheers!
–
CHEN, Cheng
hi guys,
i am curious if there is the concept of ‘set’ in q, or we just use a sorted list?
cheers!
–
CHEN, Cheng
> i am curious if there is the concept of ‘set’ in q, or we just use a sorted list?
dictionaries are like a set:
q)show s:a
b!0 0
a| 0
b| 0
q)key s
a
b
q)s`a
0
q)s`c
0N
q)s[`c]:0
q)key s
a
b`c
q)s[`b]:0
q)key s
a
b`c
q)`a in key s
1b
q)`d in key s
0b
simple intersection is
q)(key s) inter a
b`z
a
b
but your suggestion of sorted lists is great for fast intersection of sets - just depends on what it costs to keep your lists sorted.
ta, jack
On Thursday, June 27, 2013 4:45:29 PM UTC-4, Felix wrote:
i am curious if there is the concept of ‘set’ in q, or we just use a sorted list?
You can use `u# attribute on a list. This will ensure that your list consists of unique elements and create a hash table for faster lookups:
q)`u#2 2 2 2
'u-fail
q)`u#1 2 3 4
`u#1 2 3 4