In C++ I can do a partial_sort(ptr1, ptr2, ptr3). After calling partial_sort. The data in [ptr1, ptr2) is sorted and smaller than those in [ptr2, ptr3). The data in [ptr2, ptr3) is left in undefined order.
Nick: Where does the number 5 come from? In partial_sort(ptr1, ptr2, ptr3), the pivot value is NOT given. The sizes of the left partition and the right partition may be deduced from the 3 pointers. To get the pivot value, you will need something like nth_element(ptr1, ptr2, ptr3).
using a c++ algorithm to solve kdb+ problems isn’t always the best solution. can you describe your problem, giving example inputs and outputs. q does not use iterators so the approaches will differ.
I think selecting the rows of the first 10% of symbols is faster in the average case. The worst case is still O(n log n) when the quotes table has only 1 symbol. I can also iterate thru all the quotes in 10 batches incrementally.
quote: genSampleQuoteMb[800];
update g#sym from quote; / O(n) incremental index construction
symList: `sym xasc select distinct sym from quote; / distinct symbol list
symList: `sym xasc select from symList where i<0.1*count symList; / first 10% of symbols
selectedQuote: symtime xasc select from quote where sym in symList[`sym]; / quotes of the first 10% of symbols, not necessarily 10% of row count but OK
symtime xasc `quote; / O(n log n) batch sorting
btw Is applying the grouped attribute really O(n)? Is it building a hash table? It seems to be faster than sorting the whole table.
On Monday, February 9, 2015 at 1:04:41 AM UTC-5, Yan Yan wrote:
Does the embedded kdb in PyQ listen on any network port?
PyQ embeds Python in kdb+, so there is no special “embedded kdb.” You get the standard kdb+ environment plus the Python interpreter. The tricky part is not to make kdb+ listen on the network port, but to make non-blocking calls to Python from within kdb+ event loop.
Here is an example that shows how to call python function from a kdb+ timer while serving kdb+ IPC on port 1111:
$ cat x.q
p)from pyq import q
p)def f():
print “hello from python”
return q(‘::’)
p)q.f = f
.z.ts:{f()}
\t 2000
$ q/m32/q x.q -p 1111 -q
hello from python
hello from python
hello from python
Now, while embedded Python prints a greeting every 2 seconds, you can interact with the same kdb+ process on localhost:1111.
This kind of usage is still considered experimental and you would typically want to use a Python web server like tornado with PyQ rather than the kdb+ built-in.