// Get the nodes whose score within the specific range
//
// If options is nil, it searchs in interval [start, end] without any limit by default
//
// Time complexity of this method is : O(log(N))
Get the nodes whose score within the specific range

If options is nil, it searchs in interval [start, end] without any limit by default

Time complexity of this method is : O(log(N))
// Get the nodes whose score within the specific range // // If options is nil it searchs in interval [ start end ] without any limit by default // // Time complexity of this method is : O ( log ( N ))
func (this *SortedSet) GetByScoreRange(start SCORE, end SCORE, options *GetByScoreRangeOptions) []*SortedSetNodeKV {
	var limit int = int((^uint(0)) >> 1)
	if options != nil && options.Limit > 0 {
		limit = options.Limit
	}
	excludeStart := options != nil && options.ExcludeStart
	excludeEnd := options != nil && options.ExcludeEnd
	reverse := start > end
	if reverse {
		start, end = end, start
		excludeStart, excludeEnd = excludeEnd, excludeStart
	}
	this.mutex.RLock()
	defer this.mutex.RUnlock()
	var nodes []*SortedSetNodeKV
	if this.length == 0 {
		return nodes
	}
	if reverse { 
		x := this.header
		if excludeEnd {
			for i := this.level - 1; i >= 0; i-- {
				for x.level[i].forward != nil &&
					x.level[i].forward.score < end {
					x = x.level[i].forward
				}
			}
		} else {
			for i := this.level - 1; i >= 0; i-- {
				for x.level[i].forward != nil &&
					x.level[i].forward.score <= end {
					x = x.level[i].forward
				}
			}
		}
		for x != nil && limit > 0 {
			if excludeStart {
				if x.score <= start {
					break
				}
			} else {
				if x.score < start {
					break
				}
			}
			next := x.backward
			nodes = append(nodes, &x.SortedSetNodeKV)
			limit--
			x = next
		}
	} else {
		x := this.header
		if excludeStart {
			for i := this.level - 1; i >= 0; i-- {
				for x.level[i].forward != nil &&
					x.level[i].forward.score <= start {
					x = x.level[i].forward
				}
			}
		} else {
			for i := this.level - 1; i >= 0; i-- {
				for x.level[i].forward != nil &&
					x.level[i].forward.score < start {
					x = x.level[i].forward
				}
			}
		}
		x = x.level[0].forward
		for x != nil && limit > 0 {
			if excludeEnd {
				if x.score >= end {
					break
				}
			} else {
				if x.score > end {
					break
				}
			}
			next := x.level[0].forward
			nodes = append(nodes, &x.SortedSetNodeKV)
			limit--
			x = next
		}
	}
	return nodes
}
func ( this * SortedSet ) GetByScoreRange ( start SCORE , end SCORE , options * GetByScoreRangeOptions ) [ ] * SortedSetNodeKV { var limit int = int ( ( ^ uint ( 0 ) ) >> 1 ) if options != nil && options . Limit > 0 { limit = options . Limit } excludeStart := options != nil && options . ExcludeStart excludeEnd := options != nil && options . ExcludeEnd reverse := start > end if reverse { start , end = end , start excludeStart , excludeEnd = excludeEnd , excludeStart } this . mutex . RLock ( ) defer this . mutex . RUnlock ( ) var nodes [ ] * SortedSetNodeKV if this . length == 0 { return nodes } if reverse { x := this . header if excludeEnd { for i := this . level - 1 ; i >= 0 ; i -- { for x . level [ i ] . forward != nil && x . level [ i ] . forward . score < end { x = x . level [ i ] . forward } } } else { for i := this . level - 1 ; i >= 0 ; i -- { for x . level [ i ] . forward != nil && x . level [ i ] . forward . score <= end { x = x . level [ i ] . forward } } } for x != nil && limit > 0 { if excludeStart { if x . score <= start { break } } else { if x . score < start { break } } next := x . backward nodes = append ( nodes , & x . SortedSetNodeKV ) limit -- x = next } } else { x := this . header if excludeStart { for i := this . level - 1 ; i >= 0 ; i -- { for x . level [ i ] . forward != nil && x . level [ i ] . forward . score <= start { x = x . level [ i ] . forward } } } else { for i := this . level - 1 ; i >= 0 ; i -- { for x . level [ i ] . forward != nil && x . level [ i ] . forward . score < start { x = x . level [ i ] . forward } } } x = x . level [ 0 ] . forward for x != nil && limit > 0 { if excludeEnd { if x . score >= end { break } } else { if x . score > end { break } } next := x . level [ 0 ] . forward nodes = append ( nodes , & x . SortedSetNodeKV ) limit -- x = next } } return nodes }
Get the nodes whose score within the specific range
Get the nodes whose score within the specific range
// prepare parameters ////////////////////////// //determine if out of range ////////////////////////// // search from end to start // search from start to end /* Current node is the last with score < or <= start. */