Struct chashmap::CHashMap [] [src]

pub struct CHashMap<K, V> { /* fields omitted */ }

A concurrent hash map.

This type defines a concurrent associative array, based on hash tables with linear probing and dynamic resizing.

The idea is to let each entry hold a multi-reader lock, effectively limiting lock contentions to writing simultaneously on the same entry, and resizing the table.

It is not an atomic or lockless hash table, since such construction is only useful in very few cases, due to limitations on in-place operations on values.

Methods

impl<K, V> CHashMap<K, V>
[src]

Create a new hash map with a certain capacity.

"Capacity" means the amount of entries the hash map can hold before reallocating. This function allocates a hash map with at least the capacity of cap.

Create a new hash map.

This creates a new hash map with some fixed initial capacity.

Get the number of entries in the hash table.

This is entirely atomic, and will not acquire any locks.

This is guaranteed to reflect the number of entries _at this particular moment.

Get the capacity of the hash table.

The capacity is equal to the number of entries the table can hold before reallocating.

Get the number of buckets of the hash table.

"Buckets" refers to the amount of potential entries in the inner table. It is different from capacity, in the sense that the map cannot hold this number of entries, since it needs to keep the load factor low.

Is the hash table empty?

Clear the map.

This clears the hash map and returns the previous version of the map.

It is relatively efficient, although it needs to write lock a RW lock.

Deprecated

Deprecated. Do not use.

Filter the map based on some predicate.

This tests every entry in the hash map by closure predicate. If it returns true, the map will retain the entry. If not, the entry will be removed.

This won't lock the table. This can be a major performance trade-off, as it means that it must lock on every table entry. However, it won't block other operations of the table, while filtering.

impl<K: PartialEq + Hash, V> CHashMap<K, V>
[src]

Get the value of some key.

This will lookup the entry of some key key, and acquire the read-only lock. This means that all other parties are blocked from writing (not reading) this value while the guard is held.

Get the (mutable) value of some key.

This will lookup the entry of some key key, and acquire the writable lock. This means that all other parties are blocked from both reading and writing this value while the guard is held.

Does the hash map contain this key?

Insert a new entry.

This inserts an entry, which the map does not already contain, into the table. If the entry exists, the old entry won't be replaced, nor will an error be returned. It will possibly introduce silent bugs.

To be more specific, it assumes that the entry does not already exist, and will simply skip to the end of the cluster, even if it does exist.

This is faster than e.g. insert, but should only be used, if you know that the entry doesn't already exist.

Warning

Only use this, if you know what you're doing. This can easily introduce very complex logic errors.

For most other purposes, use insert.

Panics

This might perform checks in debug mode testing if the key exists already.

Replace an existing entry, or insert a new one.

This will replace an existing entry and return the old entry, if any. If no entry exists, it will simply insert the new entry and return None.

Insert or update.

This looks up key. If it exists, the reference to its value is passed through closure update. If it doesn't exist, the result of closure insert is inserted.

Map or insert an entry.

This sets the value associated with key key to f(Some(old_val)) (if it returns None, the entry is removed) if it exists. If it does not exist, it inserts it with value f(None), unless the closure returns None.

Note that if f returns None, the entry of key key is removed unconditionally.

Remove an entry.

This removes and returns the entry with key key. If no entry with said key exists, it will simply return None.

Reserve additional space.

This reserves additional additional buckets to the table. Note that it might reserve more in order make reallocation less common.

Shrink the capacity of the map to reduce space usage.

This will shrink the capacity of the map to the needed amount (plus some additional space to avoid reallocations), effectively reducing memory usage in cases where there is excessive space.

It is healthy to run this once in a while, if the size of your hash map changes a lot (e.g. has a high maximum case).

Trait Implementations

impl<K, V> Default for CHashMap<K, V>
[src]

Returns the "default value" for a type. Read more

impl<K: Clone, V: Clone> Clone for CHashMap<K, V>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<K: Debug, V: Debug> Debug for CHashMap<K, V>
[src]

Formats the value using the given formatter.

impl<K, V> IntoIterator for CHashMap<K, V>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<K: PartialEq + Hash, V> FromIterator<(K, V)> for CHashMap<K, V>
[src]

Creates a value from an iterator. Read more