From d58cb5d1f6eaee02846b39f5e1c71e70e0f4851a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 2 Jun 2014 18:04:38 +0200 Subject: [PATCH] add myPostingLast This is useful for copying an entire posting list such as when merging multiple index files into a new one. --- index/myvarint.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/index/myvarint.go b/index/myvarint.go index 8842a7c..a344fcc 100644 --- a/index/myvarint.go +++ b/index/myvarint.go @@ -99,6 +99,18 @@ int cPostingOr(const uint8_t *restrict list, return oidx; } +int cPostingLast(const uint8_t *restrict list, + uint32_t count, + uint32_t fileid, + uint32_t *totalbytes) { + const uint8_t *restrict start = list; + while (count--) { + fileid += uvarint(&list); + } + *totalbytes = (list - start); + return fileid; +} + */ import "C" @@ -165,3 +177,16 @@ func myPostingOr(data []byte, count int, list []uint32, restrict []uint32) []uin restrictptr) return result[0:int(num)] } + +func myPostingLast(data []byte, count uint32, fileid uint32) (int, uint32) { + var dataptr *C.uint8_t + if count > 0 { + dataptr = (*C.uint8_t)(&data[0]) + } + var totalbytes uint32 + last := int(C.cPostingLast(dataptr, + C.uint32_t(count), + C.uint32_t(fileid), + (*C.uint32_t)(&totalbytes))) + return last, totalbytes +} -- 2.11.4.GIT