more meaningful names for serializedStringTuples and stringTuples (#377)
more meaningful names for serializedStringTuples and stringTuples structs Signed-off-by: knrt10 <tripathi.kautilya@gmail.com> Co-authored-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
parent
043e3bb5f9
commit
3fd6d2f920
|
@ -394,7 +394,7 @@ func (w *Writer) WriteLabelIndex(names []string, values []string) error {
|
||||||
w.buf2.putBE32int(valt.Len())
|
w.buf2.putBE32int(valt.Len())
|
||||||
|
|
||||||
// here we have an index for the symbol file if v2, otherwise it's an offset
|
// here we have an index for the symbol file if v2, otherwise it's an offset
|
||||||
for _, v := range valt.s {
|
for _, v := range valt.entries {
|
||||||
index, ok := w.symbols[v]
|
index, ok := w.symbols[v]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.Errorf("symbol entry for %q does not exist", v)
|
return errors.Errorf("symbol entry for %q does not exist", v)
|
||||||
|
@ -870,9 +870,9 @@ func (r *Reader) LabelValues(names ...string) (StringTuples, error) {
|
||||||
return nil, errors.Wrap(d.err(), "read label value index")
|
return nil, errors.Wrap(d.err(), "read label value index")
|
||||||
}
|
}
|
||||||
st := &serializedStringTuples{
|
st := &serializedStringTuples{
|
||||||
l: nc,
|
idsCount: nc,
|
||||||
b: d.get(),
|
idsBytes: d.get(),
|
||||||
lookup: r.lookupSymbol,
|
lookup: r.lookupSymbol,
|
||||||
}
|
}
|
||||||
return st, nil
|
return st, nil
|
||||||
}
|
}
|
||||||
|
@ -936,33 +936,33 @@ func (r *Reader) SortedPostings(p Postings) Postings {
|
||||||
}
|
}
|
||||||
|
|
||||||
type stringTuples struct {
|
type stringTuples struct {
|
||||||
l int // tuple length
|
length int // tuple length
|
||||||
s []string // flattened tuple entries
|
entries []string // flattened tuple entries
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStringTuples(s []string, l int) (*stringTuples, error) {
|
func NewStringTuples(entries []string, length int) (*stringTuples, error) {
|
||||||
if len(s)%l != 0 {
|
if len(entries)%length != 0 {
|
||||||
return nil, errors.Wrap(errInvalidSize, "string tuple list")
|
return nil, errors.Wrap(errInvalidSize, "string tuple list")
|
||||||
}
|
}
|
||||||
return &stringTuples{s: s, l: l}, nil
|
return &stringTuples{entries: entries, length: length}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *stringTuples) Len() int { return len(t.s) / t.l }
|
func (t *stringTuples) Len() int { return len(t.entries) / t.length }
|
||||||
func (t *stringTuples) At(i int) ([]string, error) { return t.s[i : i+t.l], nil }
|
func (t *stringTuples) At(i int) ([]string, error) { return t.entries[i : i+t.length], nil }
|
||||||
|
|
||||||
func (t *stringTuples) Swap(i, j int) {
|
func (t *stringTuples) Swap(i, j int) {
|
||||||
c := make([]string, t.l)
|
c := make([]string, t.length)
|
||||||
copy(c, t.s[i:i+t.l])
|
copy(c, t.entries[i:i+t.length])
|
||||||
|
|
||||||
for k := 0; k < t.l; k++ {
|
for k := 0; k < t.length; k++ {
|
||||||
t.s[i+k] = t.s[j+k]
|
t.entries[i+k] = t.entries[j+k]
|
||||||
t.s[j+k] = c[k]
|
t.entries[j+k] = c[k]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *stringTuples) Less(i, j int) bool {
|
func (t *stringTuples) Less(i, j int) bool {
|
||||||
for k := 0; k < t.l; k++ {
|
for k := 0; k < t.length; k++ {
|
||||||
d := strings.Compare(t.s[i+k], t.s[j+k])
|
d := strings.Compare(t.entries[i+k], t.entries[j+k])
|
||||||
|
|
||||||
if d < 0 {
|
if d < 0 {
|
||||||
return true
|
return true
|
||||||
|
@ -975,23 +975,23 @@ func (t *stringTuples) Less(i, j int) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type serializedStringTuples struct {
|
type serializedStringTuples struct {
|
||||||
l int
|
idsCount int
|
||||||
b []byte
|
idsBytes []byte // bytes containing the ids pointing to the string in the lookup table.
|
||||||
lookup func(uint32) (string, error)
|
lookup func(uint32) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *serializedStringTuples) Len() int {
|
func (t *serializedStringTuples) Len() int {
|
||||||
return len(t.b) / (4 * t.l)
|
return len(t.idsBytes) / (4 * t.idsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *serializedStringTuples) At(i int) ([]string, error) {
|
func (t *serializedStringTuples) At(i int) ([]string, error) {
|
||||||
if len(t.b) < (i+t.l)*4 {
|
if len(t.idsBytes) < (i+t.idsCount)*4 {
|
||||||
return nil, errInvalidSize
|
return nil, errInvalidSize
|
||||||
}
|
}
|
||||||
res := make([]string, 0, t.l)
|
res := make([]string, 0, t.idsCount)
|
||||||
|
|
||||||
for k := 0; k < t.l; k++ {
|
for k := 0; k < t.idsCount; k++ {
|
||||||
offset := binary.BigEndian.Uint32(t.b[(i+k)*4:])
|
offset := binary.BigEndian.Uint32(t.idsBytes[(i+k)*4:])
|
||||||
|
|
||||||
s, err := t.lookup(offset)
|
s, err := t.lookup(offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue