// Get nodes within specific rank range [start, end]
// Note that the rank is 1-based integer. Rank 1 means the first node; Rank -1 means the last node;
//
// If start is greater than end, the returned array is in reserved order
// If remove is true, the returned nodes are removed
//
// Time complexity of this method is : O(log(N))
Get nodes within specific rank range [start, end]
Note that the rank is 1-based integer. Rank 1 means the first node; Rank -1 means the last node.

If start is greater than end, the returned array is in reserved order
If remove is true, the returned nodes are removed

Time complexity of this method is : O(log(N))
// Get nodes within specific rank range [ start end ] // Note that the rank is 1 - based integer . Rank 1 means the first node ; Rank - 1 means the last node ; // // If start is greater than end the returned array is in reserved order // If remove is true the returned nodes are removed // // Time complexity of this method is : O ( log ( N ))
func (this *SortedSet) GetByRankRange(start int, end int, remove bool) []*SortedSetNodeKV {
	if start < 0 {
		start = int(this.length) + start + 1
	}
	if end < 0 {
		end = int(this.length) + end + 1
	}
	if start <= 0 {
		start = 1
	}
	if end <= 0 {
		end = 1
	}
	reverse := start > end
	if reverse { 
		start, end = end, start
	}
	if remove {
		this.mutex.Lock()
		defer this.mutex.Unlock()
	} else {
		this.mutex.RLock()
		defer this.mutex.RUnlock()
	}
	var update [SKIPLIST_MAXLEVEL]*SortedSetNode
	var nodes []*SortedSetNodeKV
	var traversed int = 0
	x := this.header
	for i := this.level - 1; i >= 0; i-- {
		for x.level[i].forward != nil &&
			traversed+int(x.level[i].span) < start {
			traversed += int(x.level[i].span)
			x = x.level[i].forward
		}
		if remove {
			update[i] = x
		} else {
			if traversed+1 == start {
				break
			}
		}
	}
	traversed++
	x = x.level[0].forward
	for x != nil && traversed <= end {
		next := x.level[0].forward
		if remove {
			kv := x.SortedSetNodeKV
			nodes = append(nodes, &kv)
			this.deleteNode(x, update)
		} else {
			nodes = append(nodes, &x.SortedSetNodeKV)
		}
		traversed++
		x = next
	}
	if reverse {
		for i, j := 0, len(nodes)-1; i < j; i, j = i+1, j-1 {
			nodes[i], nodes[j] = nodes[j], nodes[i]
		}
	}
	return nodes
}
func ( this * SortedSet ) GetByRankRange ( start int , end int , remove bool ) [ ] * SortedSetNodeKV { if start < 0 { start = int ( this . length ) + start + 1 } if end < 0 { end = int ( this . length ) + end + 1 } if start <= 0 { start = 1 } if end <= 0 { end = 1 } reverse := start > end if reverse { start , end = end , start } if remove { this . mutex . Lock ( ) defer this . mutex . Unlock ( ) } else { this . mutex . RLock ( ) defer this . mutex . RUnlock ( ) } var update [ SKIPLIST_MAXLEVEL ] * SortedSetNode var nodes [ ] * SortedSetNodeKV var traversed int = 0 x := this . header for i := this . level - 1 ; i >= 0 ; i -- { for x . level [ i ] . forward != nil && traversed + int ( x . level [ i ] . span ) < start { traversed += int ( x . level [ i ] . span ) x = x . level [ i ] . forward } if remove { update [ i ] = x } else { if traversed + 1 == start { break } } } traversed ++ x = x . level [ 0 ] . forward for x != nil && traversed <= end { next := x . level [ 0 ] . forward if remove { kv := x . SortedSetNodeKV nodes = append ( nodes , & kv ) this . deleteNode ( x , update ) } else { nodes = append ( nodes , & x . SortedSetNodeKV ) } traversed ++ x = next } if reverse { for i , j := 0 , len ( nodes ) - 1 ; i < j ; i , j = i + 1 , j - 1 { nodes [ i ] , nodes [ j ] = nodes [ j ] , nodes [ i ] } } return nodes }
Get nodes within specific rank range [start, end]
Note that the rank is 1-based integer.
Get nodes within specific rank range [ start end ] Note that the rank is 1 - based integer .
/* Sanitize indexes. */ // swap start and end