Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x, 1.21.x, 1.22.x]
go-version: [1.23.x, 1.24.x, 1.25.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
Expand Down
35 changes: 34 additions & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package index
import (
"bytes"
"context"
"encoding/binary"
"fmt"
"reflect"
)

Expand Down Expand Up @@ -185,17 +187,48 @@ func (tfv *TermFieldVector) Size() int {
len(tfv.Field) + len(tfv.ArrayPositions)*sizeOfUint64
}

// IndexInternalID is an opaque document identifier interal to the index impl
// IndexInternalID is an opaque document identifier internal to the index impl
type IndexInternalID []byte

// NewIndexInternalID encodes a uint64 into an 8-byte big-endian ID, reusing `buf` when possible.
func NewIndexInternalID(buf []byte, in uint64) IndexInternalID {
if len(buf) != 8 {
if cap(buf) >= 8 {
buf = buf[0:8]
} else {
buf = make([]byte, 8)
}
}
binary.BigEndian.PutUint64(buf, in)
return buf
}

// NewIndexInternalIDFrom creates a new IndexInternalID by copying from `other`, reusing `buf` when possible.
func NewIndexInternalIDFrom(buf IndexInternalID, other IndexInternalID) IndexInternalID {
buf = buf[:0]
return append(buf, other...)
}

// Equals checks if two IndexInternalID values are equal.
func (id IndexInternalID) Equals(other IndexInternalID) bool {
return id.Compare(other) == 0
}

// Compare compares two IndexInternalID values lexicographically. For IDs created
// by NewIndexInternalID, this comparison order matches the order of their uint64 values
// due to big-endian encoding.
func (id IndexInternalID) Compare(other IndexInternalID) int {
return bytes.Compare(id, other)
}

// Value returns the uint64 value encoded in the IndexInternalID.
func (id IndexInternalID) Value() (uint64, error) {
if len(id) != 8 {
return 0, fmt.Errorf("wrong len for IndexInternalID: %q", id)
}
return binary.BigEndian.Uint64(id), nil
}

type TermFieldDoc struct {
Term string
ID IndexInternalID
Expand Down
Loading