holdme

package module
v0.0.0-...-df2960b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2017 License: BSD-3-Clause Imports: 1 Imported by: 2

README

Hold Me

Experimental: No stable version of this package yet exists; it is still in early development.

Package holdme contains some generic structures for holding values. I plan to add to this over time as I need things.

API Documentation

This is the latest development area for the package.
Eventually a stable version of the package will be established but, for now, all things about this package are subject to change.

Copyright See AUTHORS. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntKeysOrderedByIntValues

type IntKeysOrderedByIntValues struct {
	Keys     []int
	Values   []int
	RandIntn func(int) int
}

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 (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 (OrderedUint32sDups) Remove

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 (OrderedUint32sNoDups) Remove

func (OrderedUint32sNoDups) String

func (slice OrderedUint32sNoDups) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL