fix: an empty set match will panic
This commit is contained in:
parent
c6873c5c04
commit
9f7a0052a8
@ -20,6 +20,7 @@ type Set struct {
|
|||||||
leaves, labelBitmap []uint64
|
leaves, labelBitmap []uint64
|
||||||
labels []byte
|
labels []byte
|
||||||
ranks, selects []int32
|
ranks, selects []int32
|
||||||
|
isEmpty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSet creates a new *Set struct, from a slice of sorted strings.
|
// NewSet creates a new *Set struct, from a slice of sorted strings.
|
||||||
@ -46,6 +47,10 @@ func NewDomainTrieSet(keys []string) *Set {
|
|||||||
sort.Strings(reserveDomains)
|
sort.Strings(reserveDomains)
|
||||||
keys = reserveDomains
|
keys = reserveDomains
|
||||||
ss := &Set{}
|
ss := &Set{}
|
||||||
|
if len(keys) == 0 {
|
||||||
|
ss.isEmpty=true
|
||||||
|
return ss
|
||||||
|
}
|
||||||
lIdx := 0
|
lIdx := 0
|
||||||
|
|
||||||
type qElt struct{ s, e, col int }
|
type qElt struct{ s, e, col int }
|
||||||
@ -79,6 +84,9 @@ func NewDomainTrieSet(keys []string) *Set {
|
|||||||
|
|
||||||
// Has query for a key and return whether it presents in the Set.
|
// Has query for a key and return whether it presents in the Set.
|
||||||
func (ss *Set) Has(key string) bool {
|
func (ss *Set) Has(key string) bool {
|
||||||
|
if ss.isEmpty{
|
||||||
|
return false
|
||||||
|
}
|
||||||
key = utils.Reverse(key)
|
key = utils.Reverse(key)
|
||||||
// no more labels in this node
|
// no more labels in this node
|
||||||
// skip character matching
|
// skip character matching
|
||||||
|
Reference in New Issue
Block a user