Hi all,It is the first day I am trying to switch from K3 to Q. But I cannotproduce the same speed on the same algorithm with Q.Could you please explain why? Thank you.file: ip.k:/ in two words: it searches if ip is in ip-ranges or notpip:{{y+256*x}/0$1_'(&“.”=s)_ s:“.”,x} / int from ip stringips:pip’0:ips.txtiprs:+{pip'1_'(&","=s)_ s:",",x}'0:
ipr.txtil:iph@!ipl _bin x}‘ips / binary search by low range andcheck with high/ to generate files/ gip:{{($x),“.”,$y}/4_draw 255}/ ipr.txt 0:{[x] gip[],",",gip[]}'!1000/
ips.txt 0:{ gip}’!1000000speed is 5676file: ip.qpip:{{y+256*x} over “I”$"."vs x}ips:pip each read0ips.txtiprs:
l xasc l xkey flip
lh!flip pip each/:","vs'read0
ipr.txt /the second question is why …pip each… does not work without /: ?\t i:{count (select[1] from iprs where l<=x,x<=h)} each ipsspeed is 10792 / What is wrong with it? table is sorted.PS: Also welcome for any better solution :)-- Regards,? Alexander.
with kdb+ “I”$ can handle dotted ip-addresses directly
q)“I”$“192.168.1.1”
-1062731519
q)pip:{{y+256*x} over “I”$"."vs x}
q)pip"192.168.1.1"
-1062731519
q)
this simplifies loading logfiles
(on a related note you may find .Q.addr and .Q.host interesting too)
Simon,Thank you, It is good thing?But how is it possible to check if select searches by l column withbinary search?(select l from iprs)
l returns sorted list s#…Regards,On Oct 30, 7:33?am, Simon Garland <si…> wrote:> with kdb+ “I”$ can handle dotted ip-addresses directly>> q)“I”$“192.168.1.1”> -1062731519>> q)pip:{{y+256*x} over “I”$".“vs x}> q)pip"192.168.1.1”> -1062731519> q)>> this simplifies loading logfiles>> (on a related note you may find .Q.addr and .Q.host interesting too)>>>>>>>> On Sat, Oct 29, 2011 at 21:00, Alexander Epifanov <inv2…> wrote:> > PS: Also welcome for any better solution :)</inv2…></si…>
Here is the complete program on K.Q is more than 4 times slower :(pip:{0I+{y+256*x}/0$1_'(&“.”=s)_ s:“.”,x} / int from ipstringips:pip’0:ips.txtiprs:+{pip'1_'(&","=s)_ s:",",x}'0:
ipr.txt\t i1:{|/(~xiprs 1}'ips / linear searchil:iph@!ipl _bin 1+x}'ips / binary search by lowrange\t i3:{~s=(x>iph@!s:ipl _bin 1+x)?0}‘ips / ^ optimized/ to generate files/ gip:{{($x),“.”,$y}/4_draw 255}/ ipr.txt 0:{[x] gip[],",",gip[]}'!1000/
ips.txt 0:{ gip}’!1000000On Oct 30, 3:14?pm, inv <inv2…> wrote:> Simon,> Thank you, It is good thing?>> But how is it possible to check if select searches by l column with> binary search?> (select l from iprs)
l returns sorted list s#…>> Regards,>> On Oct 30, 7:33?am, Simon Garland <si…> wrote:>>>>>>>> > with kdb+ “I”$ can handle dotted ip-addresses directly>> > q)“I”$“192.168.1.1”> > -1062731519>> > q)pip:{{y+256*x} over “I”$".“vs x}> > q)pip"192.168.1.1”> > -1062731519> > q)>> > this simplifies loading logfiles>> > (on a related note you may find .Q.addr and .Q.host interesting too)>> > On Sat, Oct 29, 2011 at 21:00, Alexander Epifanov <inv2…> wrote:> > > PS: Also welcome for any better solution :)</inv2…></si…></inv2…>