blob: 594ffeaad49bd6908562ad9af1eb124a0de68383 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package nosql
type RowRange interface {
Start() string
Limit() string
}
type PrefixRange interface {
RowRange
Prefix() string
}
type rowRange struct {
start string
limit string
}
func (r *rowRange) Start() string {
return r.start
}
func (r *rowRange) Limit() string {
return r.limit
}
func SingleRow(row string) RowRange {
return &rowRange{start: row, limit: row + "\x00"}
}
func Range(start, limit string) RowRange {
return &rowRange{start: start, limit: limit}
}
// prefixRange implements the PrefixRange interface (and thus also the RowRange
// interface). We do not represent a prefix as a rowRange because we want to be
// able to distinguish prefixes from ranges (e.g. syncgroups work with prefixes,
// not ranges).
type prefixRange struct {
prefix string
}
func (r *prefixRange) Start() string {
return r.prefix
}
func (r *prefixRange) Limit() string {
p := r.prefix
if p == "" {
return p
}
// TODO(sadovsky): Special handling for delimiters or other reserved chars?
// TODO(sadovsky): This implementation is incorrect if we allow prefix strings
// to contain bytes with the max possible value (255). In practice we may
// disallow such byte values, but in any case it's probably best to make this
// implementation defensive.
return p[:len(p)-1] + string(p[len(p)-1]+1)
}
func (r *prefixRange) Prefix() string {
return r.prefix
}
func Prefix(prefix string) PrefixRange {
return &prefixRange{prefix: prefix}
}