Differences From:
File
src/descendents.c
part of check-in
[e15fe43153]
- A new decendent finding algorithm is (hopefully) faster. Changes to
the timeline are in process and might not yet work.
by
drh on
2007-08-31 20:14:33.
[view]
To:
File
src/descendents.c
part of check-in
[abce5105e2]
- Updates to the timeline routines. Added the pqueue module.
by
drh on
2007-09-01 01:55:50.
Also file
src/descendents.c
part of check-in
[bbcb6326c9]
- Pulled in the navbar and timeline changes.
by
aku on
2007-09-17 00:58:51.
[view]
@@ -67,8 +67,67 @@
}
}
bag_clear(&pending);
bag_clear(&seen);
+}
+
+/*
+** Load the record ID rid and up to N-1 closest ancestors into
+** the "ok" table.
+*/
+void compute_ancestors(int rid, int N){
+ Bag seen;
+ PQueue queue;
+ bag_init(&seen);
+ pqueue_init(&queue);
+ bag_insert(&seen, rid);
+ pqueue_insert(&queue, rid, 0.0);
+ while( (N--)>0 && (rid = pqueue_extract(&queue))!=0 ){
+ Stmt q;
+ db_multi_exec("INSERT OR IGNORE INTO ok VALUES(%d)", rid);
+ db_prepare(&q,
+ "SELECT a.pid, b.mtime FROM plink a LEFT JOIN plink b ON b.cid=a.pid"
+ " WHERE a.cid=%d", rid
+ );
+ while( db_step(&q)==SQLITE_ROW ){
+ int pid = db_column_int(&q, 0);
+ double mtime = db_column_double(&q, 1);
+ if( bag_insert(&seen, pid) ){
+ pqueue_insert(&queue, pid, -mtime);
+ }
+ }
+ db_finalize(&q);
+ }
+ bag_clear(&seen);
+ pqueue_clear(&queue);
+}
+
+/*
+** Load the record ID rid and up to N-1 closest descendents into
+** the "ok" table.
+*/
+void compute_descendents(int rid, int N){
+ Bag seen;
+ PQueue queue;
+ bag_init(&seen);
+ pqueue_init(&queue);
+ bag_insert(&seen, rid);
+ pqueue_insert(&queue, rid, 0.0);
+ while( (N--)>0 && (rid = pqueue_extract(&queue))!=0 ){
+ Stmt q;
+ db_multi_exec("INSERT OR IGNORE INTO ok VALUES(%d)", rid);
+ db_prepare(&q,"SELECT cid, mtime FROM plink WHERE pid=%d", rid);
+ while( db_step(&q)==SQLITE_ROW ){
+ int pid = db_column_int(&q, 0);
+ double mtime = db_column_double(&q, 1);
+ if( bag_insert(&seen, pid) ){
+ pqueue_insert(&queue, pid, mtime);
+ }
+ }
+ db_finalize(&q);
+ }
+ bag_clear(&seen);
+ pqueue_clear(&queue);
}
/*
** COMMAND: leaves