Hi all - enjoying this mailgroup a lot - thanks for all the useful input! Two questions:
1) Given the below, is there a faster solution to find the oldest record?
I'm assuming a large partitioned table and a maximum timeframe of 50 years.
2) Is there a prettier way to find out if there's a record for a given date?
(I'm still finding out about grepping the directory structure on disk, i.e. do we have
a non-empty file /tmp/db/1995.01.01/t/date)
---------------------
create:{[size;date]
sym: `$":/tmp/db/",(string date),"/t/";
t:([] date:x+00:30*til size; price:size?10);
sym set t
}
/ 10000 directories - 110MB - uncomment to generate:
/ create[100] each .z.D - til 10000
/ is there a prettier way?
check:{0 < first exec cnt from select cnt: count date from t where date=x}
/ x is the search window which will be repeatedly halved
find:{
/ generate halfway marks for search
steps: reverse {2*x}\[x>;1];
/ if date exists, turn left, else return right
{$[check x;x-y;x+y]}/[.z.D;steps]}
system("l /tmp/db")
show "binary search"
\t find[100*365]
/ 2 ms on my Mac
show "select min date from t"
\t select min date from t
/ 480 ms on my Mac