+ }
+ assert(pp->level>0);
+ close_block(pp->isamb, pp->block[pp->level]);
+ pp->block[pp->level] = 0;
+ (pp->level)--;
+ p = pp->block[pp->level];
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_climb_level climbed to level %d node %d ofs=%d",
+ pp->level, p->pos, p->offset);
+#endif
+ assert(!p->leaf);
+ assert(p->offset <= p->size);
+ if (p->offset == p->size)
+ {
+ /* we came from the last pointer, climb on */
+ if (!isamb_pp_climb_level(pp, pos))
+ return 0;
+ p = pp->block[pp->level];
+ }
+ else
+ {
+#if INT_ENCODE
+ char file_item_buf[DST_ITEM_MAX];
+ char *file_item = file_item_buf;
+ ISAMB b = pp->isamb;
+ void *c1 = (*b->method->codec.start)();
+#else
+ zint item_len;
+#endif
+ /* skip the child we just came from */
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isam_pp_climb_level: skipping lev=%d ofs=%d sz=%d",
+ pp->level, p->offset, p->size);
+#endif
+ assert(p->offset < p->size);
+ src = p->bytes + p->offset;
+#if INT_ENCODE
+ (*b->method->codec.decode)(c1, &file_item, &src);
+ (*b->method->codec.stop)(c1);
+#else
+ decode_item_len(&src, &item_len);
+ src += item_len;
+#endif
+ decode_ptr(&src, pos);
+ p->offset = src - (char *)p->bytes;
+
+ }
+ return 1;
+} /* climb_level */
+
+
+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 */
+ {