Alias for MutablePrimArray s Int.
Modulevector-hashtables-0.1.2.0Haskell2010
Data.Vector.Hashtables.Internal
- 5 types
- 1 class
- 52 values
- Packagevector-hashtables-0.1.2.0
- Exports58
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceInternal.hs
Single-element mutable array of Dictionary_ with primitive state token parameterized with state, keys and values types.
Different flavors of MVector could be used for keys and values.
It's preferable to use Data.Vector.Unboxed.Mutable
or Data.Vector.Storable.Mutable if possible. Otherwise,
if you must use boxed vectors, consider employing strict ones from
strict-containers
to eliminate potential accumulation of thunks.
Example
import qualified Data.Vector.Storable.Mutable as VMimport qualified Data.Vector.Unboxed.Mutable as UMimport Data.Vector.Hashtablestype HashTable k v = Dictionary (PrimState IO) VM.MVector k UM.MVector v
Constructors
DRefgetDRef :: MutVar s (Dictionary_ s ks k vs v)
Represents immutable dictionary as collection of immutable arrays and vectors. See unsafeFreeze and unsafeThaw for conversions from/to mutable dictionary.
Instances3Eq, Ord, Show
(Eq (ks k), Eq (vs v)) => Eq (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal(Ord (ks k), Ord (vs v)) => Ord (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal(Show (ks k), Show (vs v)) => Show (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal
O(1) in the best case, O(n) in the worst case.
Find dictionary entry by given key in immutable FrozenDictionary.
If entry not found -1 returned.
Infix version of unsafeRead.
Infix version of unsafeIndex.
Infix version of unsafeWrite.
Infix version of readPrimArray.
Infix version of indexPrimArray.
Infix version of writePrimArray.
O(1) Dictionary with given capacity.
Create a copy of mutable dictionary.
O(1) Unsafe convert a mutable dictionary to an immutable one without copying. The mutable dictionary may not be used after this operation.
O(1) Unsafely convert immutable FrozenDictionary to a mutable Dictionary without copying. The immutable dictionary may not be used after this operation.
O(n) Retrieve list of keys from Dictionary.
O(n) Retrieve list of values from Dictionary.
O(1) in the best case, O(n) in the worst case. Find value by given key in Dictionary. Throws an error if value not found.
O(1) in the best case, O(n) in the worst case. Find value by given key in Dictionary. Like at' but return Nothing if value not found.
O(1) in the best case, O(n) in the worst case.
Find dictionary entry by given key. If entry not found -1 returned.
O(1) in the best case, O(n) in the worst case. Same as findEntry, but for Dictionary_.
O(1) in the best case, O(n) in the worst case. Insert key and value in dictionary by key's hash. If entry with given key found value will be replaced.
insertWithIndex :: (MVector ks k, MVector vs v, PrimMonad m, Hashable k, Eq k)=> IntTarget bucket, key's hash modulo table size
-> IntKey's hash
-> kKey
-> vValue
-> MutVar (PrimState m) (Dictionary_ (PrimState m) ks k vs v)MutVar with Dictionary_
-> Dictionary_ (PrimState m) ks k vs vDictionary_ itself
-> Int-> m ()
addOrResize :: (MVector ks k, MVector vs v, PrimMonad m, Hashable k, Eq k)=> IntTarget bucket, key's hash modulo table size
-> IntKey's hash
-> kKey
-> vValue
-> MutVar (PrimState m) (Dictionary_ (PrimState m) ks k vs v)MutVar with Dictionary_
-> Dictionary_ (PrimState m) ks k vs vDictionary_ itself
-> m ()
resize :: (MVector ks k, MVector vs v, PrimMonad m, Hashable k, Eq k)=> Dictionary_ (PrimState m) ks k vs vThe original Dictionary_
-> Int-> IntKey's hash
-> kKey
-> vValue
-> m (Dictionary_ (PrimState m) ks k vs v)
Methods
deleteEntry :: (MVector xs x, PrimMonad m) => xs (PrimState m) x -> Int -> m ()
Instances3DeleteEntry
DeleteEntry MVectorDefined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.InternalDeleteEntry MVectorDefined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.InternalDeleteEntry MVectorDefined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal
O(1) in the best case, O(n) in the worst case. Delete entry from Dictionary by given key.
O(1) in the best case, O(n) in the worst case. Find value by given key in Dictionary. Like lookup' but return Nothing if value not found.
O(1) in the best case, O(n) in the worst case. Find value by given key in Dictionary. Throws an error if value not found.
O(1) in the best case, O(n) in the worst case. Lookup the index of a key, which is its zero-based index in the sequence sorted by keys. The index is a number from 0 up to, but not including, the size of the dictionary.
O(1) Return the number of non-empty entries of dictionary.
O(1) Return the number of non-empty entries of dictionary. Synonym of length.
O(1) in the best case, O(n) in the worst case.
The expression findWithDefault ht def k returns
the value at key k or returns default value def
when the key is not in the dictionary.
O(1) in the best case, O(n) in the worst case.
The expression (upsert ht f k) updates or inserts the value x at k.
It's a responsibility of MVector vs to force evaluation of the updated value.
Unboxed / storable vectors do it automatically. If you use boxed vectors,
consider employing strict ones from
strict-containers
to eliminate potential accumulation of thunks.
let f _ = "c"
ht <- fromList [(5,"a"), (3,"b")]
upsert ht f 7
toList ht
[(3, "b"), (5, "a"), (7, "c")]ht <- fromList [(5,"a"), (3,"b")]
upsert ht f 5
toList ht
[(3, "b"), (5, "c")]O(1) in the best case, O(n) in the worst case.
The expression (alter ht f k) alters the value x at k, or absence thereof.
alter can be used to insert, delete, or update a value in a Dictionary.
It's a responsibility of MVector vs to force evaluation of the updated value.
Unboxed / storable vectors do it automatically. If you use boxed vectors,
consider employing strict ones from
strict-containers
to eliminate potential accumulation of thunks.
let f _ = Nothing
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 7
toList ht
[(3, "b"), (5, "a")]ht <- fromList [(5,"a"), (3,"b")]
alter ht f 5
toList ht
[(3 "b")]let f _ = Just "c"
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 7
toList ht
[(3, "b"), (5, "a"), (7, "c")]ht <- fromList [(5,"a"), (3,"b")]
alter ht f 5
toList ht
[(3, "b"), (5, "c")]O(1) in the best case, O(n) in the worst case.
The expression (alterM ht f k) alters the value x at k, or absence thereof.
alterM can be used to insert, delete, or update a value in a Dictionary in the same PrimMonad m.
Combine
3 declarationsO(min n m) in the best case, O(min n m * max n m) in the worst case. The union of two maps. If a key occurs in both maps, the mapping from the first will be the mapping in the result.
O(min n m) in the best case, O(min n m * max n m) in the worst case. The union of two maps. The provided function (first argument) will be used to compute the result.
O(min n m) in the best case, O(min n m * max n m) in the worst case. The union of two maps. If a key occurs in both maps, the provided function (first argument) will be used to compute the result.
Difference and intersection
5 declarationsO(n) in the best case, O(n * m) in the worst case. Difference of two tables. Return elements of the first table not existing in the second.
O(n) in the best case, O(n * m) in the worst case.
Difference with a combining function. When two equal keys are
encountered, the combining function is applied to the values of these keys.
If it returns Nothing, the element is discarded (proper set difference). If
it returns (Just y), the element is updated with a new value y.
O(n) in the best case, O(n * m) in the worst case. Intersection of two maps. Return elements of the first map for keys existing in the second.
Intersection of two maps. If a key occurs in both maps the provided function is used to combine the values from the two maps.
Intersection of two maps. If a key occurs in both maps the provided function is used to combine the values from the two maps.
List conversions
2 declarationsO(n) Convert list to a Dictionary.
O(n) Convert Dictionary to a list.