+static zint isamb_pp_forward_unode(ISAMB_PP pp, zint pos, const void *untilbuf)
+{ /* scans a upper node until it finds a child <= untilbuf */
+ /* pp points to the key value, as always. pos is the child read from */
+ /* the buffer */
+ /* if all values are too small, returns the last child in the node */
+ /* FIXME - this can be detected, and avoided by looking at the */
+ /* parent node, but that gets messy. Presumably the cost is */
+ /* pretty low anyway */
+ ISAMB b = pp->isamb;
+ struct ISAMB_block *p = pp->block[pp->level];
+ const char *src = p->bytes + p->offset;
+ int cmp;
+ zint nxtpos;
+#if ISAMB_DEBUG
+ int skips = 0;
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward_unode starting "
+ "at level %d node %d ofs=%di sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ assert(!p->leaf);
+ assert(p->offset <= p->size);
+ if (p->offset == p->size)
+ {
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward_unode returning at end "
+ "at level %d node %d ofs=%di sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ return pos; /* already at the end of it */
+ }
+ while(p->offset < p->size)
+ {
+#if INT_ENCODE
+ char file_item_buf[DST_ITEM_MAX];
+ char *file_item = file_item_buf;
+ void *c1 = (*b->method->codec.start)();
+ (*b->method->codec.decode)(c1, &file_item, &src);
+ (*b->method->codec.stop)(c1);
+ cmp = (*b->method->compare_item)(untilbuf, file_item_buf);
+#else
+ zint item_len;
+ decode_item_len(&src, &item_len);
+ cmp = (*b->method->compare_item)(untilbuf, src);
+ src += item_len;
+#endif
+ decode_ptr(&src, &nxtpos);
+ if (cmp<pp->scope) /* cmp<2 */
+ {
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward_unode returning a hit "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ return pos;
+ } /* found one */
+ pos = nxtpos;
+ p->offset = src-(char*)p->bytes;
+ (pp->skipped_nodes[pp->maxlevel - pp->level -1])++;
+#if ISAMB_DEBUG
+ skips++;
+#endif
+ }
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward_unode returning at tail "
+ "at level %d node %d ofs=%d sz=%d skips=%d",
+ pp->level, p->pos, p->offset, p->size, skips);
+#endif
+ return pos; /* that's the last one in the line */
+
+} /* forward_unode */
+
+static void isamb_pp_descend_to_leaf(ISAMB_PP pp, ISAM_P pos,
+ const void *untilbuf)