If 'p' points to an element of the listpack, calling lpPrev() will return * the pointer to the previous element (the one on the left), or NULL if 'p' * already pointed to the first element of the listpack. */
| 464 | * the pointer to the previous element (the one on the left), or NULL if 'p' |
| 465 | * already pointed to the first element of the listpack. */ |
| 466 | unsigned char *lpPrev(unsigned char *lp, unsigned char *p) { |
| 467 | assert(p); |
| 468 | if (p-lp == LP_HDR_SIZE) return NULL; |
| 469 | p--; /* Seek the first backlen byte of the last element. */ |
| 470 | uint64_t prevlen = lpDecodeBacklen(p); |
| 471 | prevlen += lpEncodeBacklen(NULL,prevlen); |
| 472 | p -= prevlen-1; /* Seek the first byte of the previous entry. */ |
| 473 | lpAssertValidEntry(lp, lpBytes(lp), p); |
| 474 | return p; |
| 475 | } |
| 476 | |
| 477 | /* Return a pointer to the first element of the listpack, or NULL if the |
| 478 | * listpack has no elements. */ |
no test coverage detected