Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IntKeysOrderedByIntValues ¶
IntKeysOrderedByIntValues keeps Keys in order by Values[Keys[i]] value.
It assumes a relatively static set in Keys that you want to keep sorted as their Values change. You first add all the keys using Add and then use Move to change the values. As you do so, Keys will be kept in order.
Note that the values of the keys are simply stored in a slice and not a map, so if you have a high key, it will use a lot of memory. It should be easy to modify to use a map if desired though; for my use, a slice was fine and much faster than a map.
The RandIntn function may be set to randomize key locations whose values are the same. Even if RandIntn is nil, the order of keys whose values are the same is not guaranteed to be in any particular order (think like Go's map key order, no guarantees).
I know it's a weird "key/value randomization bag" or something and probably not generally useful, but I had to create it for my github.com/gholt/ring/lowring package where I needed to sort nodes and groups by their desires, so here it is.
This code will copy memory quite a bit and can probably be improved with scanning for value runs and swapping. Of course, if there are few runs, swapping "by hand" will probably be slower than just calling copy. Not sure yet, just haven't gotten that far. Oh, and another note if you (or future me) decides to try this optimization, you'll have to swap before applying the RandIntn, and then use that to swap a second time.
func NewIntKeysOrderedByIntValues ¶
func NewIntKeysOrderedByIntValues(cap int, randIntn func(int) int) *IntKeysOrderedByIntValues
func (*IntKeysOrderedByIntValues) Add ¶
func (x *IntKeysOrderedByIntValues) Add(key int, value int)
func (*IntKeysOrderedByIntValues) Move ¶
func (x *IntKeysOrderedByIntValues) Move(key int, value int)
func (*IntKeysOrderedByIntValues) String ¶
func (x *IntKeysOrderedByIntValues) String() string
type OrderedIntsDups ¶
type OrderedIntsDups []int
OrderedIntsDups keeps a list of ints in order, allowing duplicates.
func (OrderedIntsDups) Add ¶
func (slice OrderedIntsDups) Add(v int) OrderedIntsDups
func (OrderedIntsDups) Remove ¶
func (slice OrderedIntsDups) Remove(v int) OrderedIntsDups
func (OrderedIntsDups) String ¶
func (slice OrderedIntsDups) String() string
type OrderedIntsNoDups ¶
type OrderedIntsNoDups []int
OrderedIntsNoDups keeps a list of ints in order, without duplicates.
func (OrderedIntsNoDups) Add ¶
func (slice OrderedIntsNoDups) Add(v int) OrderedIntsNoDups
func (OrderedIntsNoDups) Remove ¶
func (slice OrderedIntsNoDups) Remove(v int) OrderedIntsNoDups
func (OrderedIntsNoDups) String ¶
func (slice OrderedIntsNoDups) String() string
type OrderedUint32sDups ¶
type OrderedUint32sDups []uint32
OrderedUint32sDups keeps a list of uint32s in order, allowing duplicates.
func (OrderedUint32sDups) Add ¶
func (slice OrderedUint32sDups) Add(v uint32) OrderedUint32sDups
func (OrderedUint32sDups) Remove ¶
func (slice OrderedUint32sDups) Remove(v uint32) OrderedUint32sDups
func (OrderedUint32sDups) String ¶
func (slice OrderedUint32sDups) String() string
type OrderedUint32sNoDups ¶
type OrderedUint32sNoDups []uint32
OrderedUint32sNoDups keeps a list of uint32s in order, without duplicates.
func (OrderedUint32sNoDups) Add ¶
func (slice OrderedUint32sNoDups) Add(v uint32) OrderedUint32sNoDups
func (OrderedUint32sNoDups) Remove ¶
func (slice OrderedUint32sNoDups) Remove(v uint32) OrderedUint32sNoDups
func (OrderedUint32sNoDups) String ¶
func (slice OrderedUint32sNoDups) String() string