go-concurrentMap: github.com/fanliao/go-concurrentMap Index | Files

package concurrent

import "github.com/fanliao/go-concurrentMap"

Index

Package Files

concurrentmap.go once.go util.go

Constants

const (
    /**
     * The default initial capacity for this table,
     * used when not otherwise specified in a constructor.
     */
    DEFAULT_INITIAL_CAPACITY int = 16

    /**
     * The default load factor for this table, used when not
     * otherwise specified in a constructor.
     */
    DEFAULT_LOAD_FACTOR float32 = 0.75

    /**
     * The default concurrency level for this table, used when not
     * otherwise specified in a constructor.
     */
    DEFAULT_CONCURRENCY_LEVEL int = 16

    /**
     * The maximum capacity, used if a higher value is implicitly
     * specified by either of the constructors with arguments.  MUST
     * be a power of two <= 1<<30 to ensure that entries are indexable
     * using ints.
     */
    MAXIMUM_CAPACITY int = 1 << 30

    /**
     * The maximum number of segments to allow; used to bound
     * constructor arguments.
     */
    MAX_SEGMENTS int = 1 << 16 // slightly conservative

    /**
     * Number of unsynchronized retries in size and containsValue
     * methods before resorting to locking. This is used to avoid
     * unbounded retries if tables undergo continuous modification
     * which would make it impossible to obtain an accurate result.
     */
    RETRIES_BEFORE_LOCK int = 2
)

Variables

var (
    Debug           = false
    NilKeyError     = errors.New("Do not support nil as key")
    NilValueError   = errors.New("Do not support nil as value")
    NilActionError  = errors.New("Do not support nil as action")
    NonSupportKey   = errors.New("Non support for pointer, interface, channel, slice, map and function ")
    IllegalArgError = errors.New("IllegalArgumentException")
)

func Printf Uses

func Printf(format string, a ...interface{}) (n int, err error)

func Println Uses

func Println(a ...interface{}) (n int, err error)

type ConcurrentMap Uses

type ConcurrentMap struct {
    // contains filtered or unexported fields
}

segments is read-only, don't need synchronized

func NewConcurrentMap Uses

func NewConcurrentMap(paras ...interface{}) (m *ConcurrentMap)

*

* Creates a new, empty map with the specified initial
* capacity, load factor and concurrency level.
*
* @param initialCapacity the initial capacity. The implementation
* performs internal sizing to accommodate this many elements.
*
* @param loadFactor  the load factor threshold, used to control resizing.
* Resizing may be performed when the average number of elements per
* bin exceeds this threshold.
*
* @param concurrencyLevel the estimated number of concurrently
* updating threads. The implementation performs internal sizing
* to try to accommodate this many threads.
*
* panic error "IllegalArgumentException" if the initial capacity is
* negative or the load factor or concurrencyLevel are
* nonpositive.
*
* Creates a new, empty map with a default initial capacity (16),
* load factor (0.75) and concurrencyLevel (16).

func NewConcurrentMapFromMap Uses

func NewConcurrentMapFromMap(m map[interface{}]interface{}) *ConcurrentMap

*

* Creates a new map with the same mappings as the given map.
* The map is created with a capacity of 1.5 times the number
* of mappings in the given map or 16 (whichever is greater),
* and a default load factor (0.75) and concurrencyLevel (16).
*
* @param m the map

func (*ConcurrentMap) Clear Uses

func (this *ConcurrentMap) Clear()

*

* Removes all of the mappings from this map.

func (*ConcurrentMap) CompareAndReplace Uses

func (this *ConcurrentMap) CompareAndReplace(key interface{}, oldVal interface{}, newVal interface{}) (ok bool, err error)

*

* CompareAndReplace executes the compare-and-replace operation.
* Replaces the value if the mapping exists for the previous and key from this map.
* This method does nothing if no mapping for the key and value.
*
* @return true if value be replaced, false otherwise

func (*ConcurrentMap) ContainsKey Uses

func (this *ConcurrentMap) ContainsKey(key interface{}) (found bool, err error)

*

* Tests if the specified object is a key in this table.
*
* @param  key   possible key
* @return true if and only if the specified object is a key in this table,
* as determined by the == method; false otherwise.

func (*ConcurrentMap) Get Uses

func (this *ConcurrentMap) Get(key interface{}) (value interface{}, err error)

*

* Returns the value to which the specified key is mapped,
* or nil if this map contains no mapping for the key.

func (*ConcurrentMap) IsEmpty Uses

func (this *ConcurrentMap) IsEmpty() bool

*

* Returns true if this map contains no key-value mappings.

func (*ConcurrentMap) Iterator Uses

func (this *ConcurrentMap) Iterator() *MapIterator

Iterator returns a iterator for ConcurrentMap

func (*ConcurrentMap) Put Uses

func (this *ConcurrentMap) Put(key interface{}, value interface{}) (oldVal interface{}, err error)

*

* Maps the specified key to the specified value in this table.
* Neither the key nor the value can be nil.
*
* The value can be retrieved by calling the get method
* with a key that is equal to the original key.
*
* @param key with which the specified value is to be associated
* @param value to be associated with the specified key
*
* @return the previous value associated with key, or
*         nil if there was no mapping for key

func (*ConcurrentMap) PutAll Uses

func (this *ConcurrentMap) PutAll(m map[interface{}]interface{}) (err error)

*

* Copies all of the mappings from the specified map to this one.
* These mappings replace any mappings that this map had for any of the
* keys currently in the specified map.
*
* @param m mappings to be stored in this map

func (*ConcurrentMap) PutIfAbsent Uses

func (this *ConcurrentMap) PutIfAbsent(key interface{}, value interface{}) (oldVal interface{}, err error)

*

* If mapping exists for the key, then maps the specified key to the specified value in this table.
* else will ignore.
* Neither the key nor the value can be nil.
*
* The value can be retrieved by calling the get method
* with a key that is equal to the original key.
*
* @return the previous value associated with the specified key,
*         or nil if there was no mapping for the key

func (*ConcurrentMap) Remove Uses

func (this *ConcurrentMap) Remove(key interface{}) (oldVal interface{}, err error)

*

* Removes the key (and its corresponding value) from this map.
* This method does nothing if the key is not in the map.
*
* @param  key the key that needs to be removed
* @return the previous value associated with key, or nil if there was no mapping for key

func (*ConcurrentMap) RemoveEntry Uses

func (this *ConcurrentMap) RemoveEntry(key interface{}, value interface{}) (ok bool, err error)

*

* Removes the mapping for the key and value from this map.
* This method does nothing if no mapping for the key and value.
*
* @return true if mapping be removed, false otherwise

func (*ConcurrentMap) Replace Uses

func (this *ConcurrentMap) Replace(key interface{}, value interface{}) (oldVal interface{}, err error)

*

* Replaces the value if the key is in the map.
* This method does nothing if no mapping for the key.
*
* @return the previous value associated with the specified key,
*         or nil if there was no mapping for the key

func (*ConcurrentMap) Size Uses

func (this *ConcurrentMap) Size() int32

*

* Returns the number of key-value mappings in this map.

func (*ConcurrentMap) ToSlice Uses

func (this *ConcurrentMap) ToSlice() (kvs []*Entry)

ToSlice returns a slice that includes all key-value Entry in ConcurrentMap

func (*ConcurrentMap) Update Uses

func (this *ConcurrentMap) Update(key interface{}, action func(oldVal interface{}) (newVal interface{})) (oldVal interface{}, err error)

*

* Maps the specified key to the value that be returned by specified function in this table.
* The key can not be nil.
*
* The value mapping specified key will be passed into action function as parameter.
* If mapping does not exists for the key, nil will be passed into action function.
* If return value by action function is nil, the specified key will be remove from map.
*
* @param key with which the specified value is to be associated
* @param action that be called to generate new value mapping the specified key
*
* @return the previous value associated with key, or
*         nil if there was no mapping for key

type Entry Uses

type Entry struct {
    // contains filtered or unexported fields
}

*

* ConcurrentHashMap list entry.
* Note only value field is variable and must use atomic to read/write it, other three fields are read-only after initializing.
* so can use unsynchronized reader, the Segment.readValueUnderLock method is used as a
* backup in case a nil (pre-initialized) value is ever seen in
* an unsynchronized access method.

func (*Entry) Key Uses

func (this *Entry) Key() interface{}

func (*Entry) Value Uses

func (this *Entry) Value() interface{}

type Hashable Uses

type Hashable interface {
    HashBytes() []byte
    Equals(v2 interface{}) bool
}

type MapIterator Uses

type MapIterator struct {
    // contains filtered or unexported fields
}

func (*MapIterator) HasNext Uses

func (this *MapIterator) HasNext() bool

func (*MapIterator) Next Uses

func (this *MapIterator) Next() (key interface{}, value interface{}, ok bool)

func (*MapIterator) Remove Uses

func (this *MapIterator) Remove() (ok bool)

type Once Uses

type Once struct {
    // contains filtered or unexported fields
}

Once is an object that will perform exactly one action.

func (*Once) Do Uses

func (o *Once) Do(f func())

Do calls the function f if and only if Do is being called for the first time for this instance of Once. In other words, given

var once Once

if once.Do(f) is called multiple times, only the first call will invoke f, even if f has a different value in each invocation. A new instance of Once is required for each function to execute.

Do is intended for initialization that must be run exactly once. Since f is niladic, it may be necessary to use a function literal to capture the arguments to a function to be invoked by Do:

config.once.Do(func() { config.init(filename) })

Because no call to Do returns until the one call to f returns, if f causes Do to be called, it will deadlock.

func (*Once) IsDone Uses

func (o *Once) IsDone() bool

type Segment Uses

type Segment struct {
    // contains filtered or unexported fields
}

Package concurrent imports 10 packages (graph) and is imported by 10 packages. Updated 2016-07-20. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).