Fast mutable and immutable associative data structures based on bitmap trie
hashmaps. Mutable pathways implement the java.util.Map
or Set
interfaces
including in-place update features such as compute or computeIfPresent.
Mutable maps or sets can be turned into their immutable counterparts via the
Clojure persistent!
call. This allows working in a mutable space for
convenience and performance then switching to an immutable pathway when
necessary. Note: after persistent!
one should never backdoor mutate map or
set again as this will break the contract of immutability. Immutable
data structures also support conversion to transient via transient
.
Map keysets (.keySet
) are full PersistentHashSet
s of keys.
Maps and sets support metadata but setting the metadata on mutable objects
returns a new mutable object that shares the backing store leading to possible
issues. Metadata is transferred to the persistent versions of the
mutable/transient objects upon persistent!
.
Very fast versions of union, difference and intersection are provided for maps
and sets with the map version of union and difference requiring an extra
argument, a java.util.BiFunction
or an IFn
taking 2 arguments to merge the
left and right sides into the final map. These implementations of union,
difference, and intersection are the fastest implementation of these
operations we know of on the JVM.
Additionally a fast value update pathway is provided, enabling quickly updating all the values in a given map. Additionally, a new map primitive
mapmap
- allows transforming a given map into a new map quickly by
mapping across all the entries.Unlike the standard Java objects, mutation-via-iterator is not supported.
Fast mutable and immutable associative data structures based on bitmap trie hashmaps. Mutable pathways implement the `java.util.Map` or `Set` interfaces including in-place update features such as compute or computeIfPresent. Mutable maps or sets can be turned into their immutable counterparts via the Clojure `persistent!` call. This allows working in a mutable space for convenience and performance then switching to an immutable pathway when necessary. Note: after `persistent!` one should never backdoor mutate map or set again as this will break the contract of immutability. Immutable data structures also support conversion to transient via `transient`. Map keysets (`.keySet`) are full `PersistentHashSet`s of keys. Maps and sets support metadata but setting the metadata on mutable objects returns a new mutable object that shares the backing store leading to possible issues. Metadata is transferred to the persistent versions of the mutable/transient objects upon `persistent!`. Very fast versions of union, difference and intersection are provided for maps and sets with the map version of union and difference requiring an extra argument, a `java.util.BiFunction` or an `IFn` taking 2 arguments to merge the left and right sides into the final map. These implementations of union, difference, and intersection are the fastest implementation of these operations we know of on the JVM. Additionally a fast value update pathway is provided, enabling quickly updating all the values in a given map. Additionally, a new map primitive - [[mapmap]] - allows transforming a given map into a new map quickly by mapping across all the entries. Unlike the standard Java objects, mutation-via-iterator is not supported.
(->bi-function cljfn)
Convert an object to a java.util.BiFunction. Object can either already be a bi-function or an IFn to be invoked with 2 arguments.
Convert an object to a java.util.BiFunction. Object can either already be a bi-function or an IFn to be invoked with 2 arguments.
(->collection item)
Ensure item is an implementation of java.util.Collection.
Ensure item is an implementation of java.util.Collection.
(->function cljfn)
Convert an object to a java Function. Object can either already be a Function or an IFn to be invoked.
Convert an object to a java Function. Object can either already be a Function or an IFn to be invoked.
(->random-access item)
Ensure item is derived from java.util.List and java.util.RandomAccess and thus supports constant time random addressing.
Ensure item is derived from java.util.List and java.util.RandomAccess and thus supports constant time random addressing.
(->reducible item)
Ensure item either implements IReduceInit or java.util.Collection. For arrays this will return an object that has a much more efficient reduction pathway than the base Clojure reducer.
Ensure item either implements IReduceInit or java.util.Collection. For arrays this will return an object that has a much more efficient reduction pathway than the base Clojure reducer.
(argsort coll)
(argsort comp coll)
Sort a collection of data returning an array of indexes. The collection must be
random access and the return value is an integer array of indexes which will read the
input data in sorted order. Faster implementations are provided when the collection
is an integer, long, or double array. See also reindex
.
Sort a collection of data returning an array of indexes. The collection must be random access and the return value is an integer array of indexes which will read the input data in sorted order. Faster implementations are provided when the collection is an integer, long, or double array. See also [[reindex]].
(array-list)
(array-list data)
Create an implementation of java.util.ArrayList.
Create an implementation of java.util.ArrayList.
(assoc m a b)
(assoc m a b c d)
(assoc m a b c d e f)
(assoc m a b c d e f g h)
(assoc m a b c d e f g h & args)
Drop in faster or equivalent replacement for clojure.core/assoc especially for small numbers of keyval pairs.
Drop in faster or equivalent replacement for clojure.core/assoc especially for small numbers of keyval pairs.
(assoc! obj k v)
assoc! that works on transient collections, implementations of java.util.Map and RandomAccess java.util.List implementations. Be sure to keep track of return value as some implementations return a different return value than the first argument.
assoc! that works on transient collections, implementations of java.util.Map and RandomAccess java.util.List implementations. Be sure to keep track of return value as some implementations return a different return value than the first argument.
(assoc-in m ks v)
Assoc-in - more efficient replacement if ks is a known compile time constant or a vector. See the caveats in the README before using this exact function.
Assoc-in - more efficient replacement if ks is a known compile time constant or a vector. See the caveats in the README before using this exact function.
(bi-function arg1 arg2 code)
Create an implementation of java.util.function.BiFunction
Create an implementation of java.util.function.BiFunction
(clear! map-or-coll)
Mutably clear a map, set, list or implementation of java.util.Collection.
Mutably clear a map, set, list or implementation of java.util.Collection.
(clear-memoized-fn! memoize-fn)
Clear a memoized function backing store.
Clear a memoized function backing store.
(compute! m k bfn)
Compute a new value in a map derived from an existing value. bfn gets passed k, v where k may be nil. If the function returns nil the corresponding key is removed from the map.
See Map.compute
An example bfn
for counting occurrences would be #(if % (inc (long %)) 1)
.
Compute a new value in a map derived from an existing value. bfn gets passed k, v where k may be nil. If the function returns nil the corresponding key is removed from the map. See [Map.compute](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#compute-K-java.util.function.BiFunction-) An example `bfn` for counting occurrences would be `#(if % (inc (long %)) 1)`.
(compute-if-absent! m k bfn)
Compute a value if absent from the map. Useful for memoize-type operations. Must use mutable maps. bfn gets passed k.
Compute a value if absent from the map. Useful for memoize-type operations. Must use mutable maps. bfn gets passed k. See [map.computeIfAbsent](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function-)
(compute-if-present! m k bfn)
Compute a new value if the value already exists and is non-nil in the hashmap. Must use mutable maps. bfn gets passed k, v where v is non-nil.
Compute a new value if the value already exists and is non-nil in the hashmap. Must use mutable maps. bfn gets passed k, v where v is non-nil. See [Map.computeIfPresent](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfPresent-K-java.util.function.BiFunction-)
(concata)
(concata v1)
(concata v1 v2)
(concata v1 v2 & args)
non-lazily concat a set of items returning an object array. This always returns an object array an may return an empty array whereas concat may return nil.
non-lazily concat a set of items returning an object array. This always returns an object array an may return an empty array whereas concat may return nil.
(concatv)
(concatv v1)
(concatv v1 v2)
(concatv v1 v2 & args)
non-lazily concat a set of items returning a persistent vector.
non-lazily concat a set of items returning a persistent vector.
(conj! obj val)
conj! that works on transient collections, implementations of java.util.Set and RandomAccess java.util.List implementations. Be sure to keep track of return value as some implementations return a different return value than the first argument.
conj! that works on transient collections, implementations of java.util.Set and RandomAccess java.util.List implementations. Be sure to keep track of return value as some implementations return a different return value than the first argument.
(constant-count data)
Constant time count. Returns nil if input doesn't have a constant time count.
Constant time count. Returns nil if input doesn't have a constant time count.
(constant-countable? data)
Return true if data has a constant time count.
Return true if data has a constant time count.
(darange end)
(darange start end)
(darange start end step)
Return a double array holding the values of the range. Useing ->collection
to get
an implementation of java.util.List that supports the normal Clojure interfaces.
Return a double array holding the values of the range. Useing `->collection` to get an implementation of java.util.List that supports the normal Clojure interfaces.
Default hash provider - currently set to the hybrid hash provider.
Default hash provider - currently set to the hybrid hash provider.
(difference map1 map2)
Take the difference of two maps (or sets) returning a new map. Return value is a map1 (or set1) without the keys present in map2.
Take the difference of two maps (or sets) returning a new map. Return value is a map1 (or set1) without the keys present in map2.
(double-array data)
Create a double array from a number of some data
Create a double array from a number of some data
(double-array-list)
(double-array-list cap-or-data)
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
(double-binary-operator lvar rvar & code)
Create a binary operator that is specialized for double values. Useful to speed up operations such as sorting or summation.
Create a binary operator that is specialized for double values. Useful to speed up operations such as sorting or summation.
(drop n coll)
Drop the first N items of the collection. If item is random access, the return value is random-access.
Drop the first N items of the collection. If item is random access, the return value is random-access.
(drop-last n coll)
Drop the last N values from a collection. IF the input is random access, the result will be random access.
Drop the last N values from a collection. IF the input is random access, the result will be random access.
(drop-min n values)
(drop-min n comp values)
Drop the min n values of a collection. This is not an order-preserving operation.
Drop the min n values of a collection. This is not an order-preserving operation.
(empty? coll)
Hash provider based on Object.hashCode and Object.equals - this is
the same pathway that java.util.HashMap
uses and is the overall the fastest
hash provider. Hash-based data structures based on this hash provider will be
faster to create and access but will not use the hasheq pathway. This is fine
for integer keys, strings, keywords, and symbols, but differs for objects such
as doubles, floats, and BigDecimals. This is the default hash provider.
Hash provider based on Object.hashCode and Object.equals - this is the same pathway that `java.util.HashMap` uses and is the overall the fastest hash provider. Hash-based data structures based on this hash provider will be faster to create and access but will not use the hasheq pathway. This is fine for integer keys, strings, keywords, and symbols, but differs for objects such as doubles, floats, and BigDecimals. This is the default hash provider.
Hash provider based on Clojure's hasheq and equiv pathways - the
same algorithm that Clojure's persistent data structures use. This hash
provider is somewhat (<2x) slower than the equal-hash-provider
.
Hash provider based on Clojure's hasheq and equiv pathways - the same algorithm that Clojure's persistent data structures use. This hash provider is somewhat (<2x) slower than the [[equal-hash-provider]].
(fast-reduce rfn iter)
(fast-reduce rfn init iter)
Version of reduce that is a bit faster for things that aren't sequences and do not implement IReduceInit.
Version of reduce that is a bit faster for things that aren't sequences and do not implement IReduceInit.
(first coll)
Get the first item of a collection.
Get the first item of a collection.
(float-array data)
Create a float array from a number of some data
Create a float array from a number of some data
(frequencies coll)
Faster implementation of clojure.core/frequencies.
Faster implementation of clojure.core/frequencies.
(get-in m ks)
(get-in m ks default-value)
get-in drop-in more efficient replacement if ks is a vector especially if ks is known at compile time.
get-in drop-in more efficient replacement if ks is a vector especially if ks is known at compile time.
(group-by f coll)
Group items in collection by the grouping function f. Returns persistent map of keys to persistent vectors.
Group items in collection by the grouping function f. Returns persistent map of keys to persistent vectors.
(group-by-reduce key-fn reduce-fn coll)
(group-by-reduce key-fn reduce-fn finalize-fn coll)
Group by key. Apply the reduce-fn the existing value and on each successive value. finalize-fn is called during finalization with that the sole argument of the existing value. If at any point result is reduced? group-by continues but further reductions for that specific value cease. In this case finalize-fn isn't called but the result is simply deref'd during finalization.
This type of reduction can be both faster and more importantly use less memory than a reduction of the forms:
(->> group-by map into)` or `(->> group-by mapmap)
ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) + (range 100))
{0 735, 1 750, 2 665, 3 679, 4 693, 5 707, 6 721}
ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) max (shuffle (range 100)))
{0 98, 1 99, 2 93, 3 94, 4 95, 5 96, 6 97}
ham-fisted.api> ;;Reduce to map of first value found
ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) (fn [l r] l) (range 100))
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6}
ham-fisted.api> ;;Reduce to map of last value found
ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) (fn [l r] r) (range 100))
{0 98, 1 99, 2 93, 3 94, 4 95, 5 96, 6 97}
Group by key. Apply the reduce-fn the existing value and on each successive value. finalize-fn is called during finalization with that the sole argument of the existing value. If at any point result is reduced? group-by continues but further reductions for that specific value cease. In this case finalize-fn isn't called but the result is simply deref'd during finalization. This type of reduction can be both faster and more importantly use less memory than a reduction of the forms: ```clojure (->> group-by map into)` or `(->> group-by mapmap) ``` ```clojure ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) + (range 100)) {0 735, 1 750, 2 665, 3 679, 4 693, 5 707, 6 721} ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) max (shuffle (range 100))) {0 98, 1 99, 2 93, 3 94, 4 95, 5 96, 6 97} ham-fisted.api> ;;Reduce to map of first value found ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) (fn [l r] l) (range 100)) {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6} ham-fisted.api> ;;Reduce to map of last value found ham-fisted.api> (group-by-reduce #(rem (unchecked-long %1) 7) (fn [l r] r) (range 100)) {0 98, 1 99, 2 93, 3 94, 4 95, 5 96, 6 97} ```
(hash-map)
(hash-map a b)
(hash-map a b c d)
(hash-map a b c d e f)
(hash-map a b c d e f g h)
(hash-map a b c d e f g h i j)
(hash-map a b c d e f g h i j k l)
(hash-map a b c d e f g h i j k l m n)
(hash-map a b c d e f g h i j k l m n o p)
(hash-map a b c d e f g h i j k l m n o p & args)
Drop-in replacement to Clojure's hash-map function.
Drop-in replacement to Clojure's hash-map function.
Hash provider opportunistically using IHashEq pathway when provided else falling back to mixhash(obj.hashCode). For equality strictly uses Util.equiv as equality has not shown up to be a profiler bottleneck while generating mumur3 compatible hashes has in some cases (integers). This hash provider provides a middle ground offering more performance for simple datatypes but still using the more robust equiv pathways for more complex datatypes. This is currently the default hash provider for the library.
Hash provider opportunistically using IHashEq pathway when provided else falling back to mixhash(obj.hashCode). For equality strictly uses Util.equiv as equality has not shown up to be a profiler bottleneck while generating mumur3 compatible hashes has in some cases (integers). This hash provider provides a middle ground offering more performance for simple datatypes but still using the more robust equiv pathways for more complex datatypes. This is currently the default hash provider for the library.
(iarange end)
(iarange start end)
(iarange start end step)
Return an integer array holding the values of the range. Use ->collection
to get a
list implementation wrapping for generic access.
Return an integer array holding the values of the range. Use `->collection` to get a list implementation wrapping for generic access.
(immut-list)
(immut-list data)
Create a persistent list. Object arrays will be treated as if this new object owns them.
Create a persistent list. Object arrays will be treated as if this new object owns them.
(immut-map)
(immut-map data)
(immut-map options data)
Create an immutable map. This object supports conversion to a transient map via
Clojure's transient
function. Duplicate keys are treated as if by assoc.
If data is an object array it is treated as a flat key-value list which is distinctly different than how conj! treats object arrays. You have been warned.
If you know you will have consistently more key/val pairs than 8 you should just
use (persistent! (mut-map data))
as that avoids the transition from an arraymap
to a persistent hashmap.
Options:
:hash-provider
- An implementation of BitmapTrieCommon$HashProvider
. Defaults to
the default-hash-provider
.Examples:
ham-fisted.api> (immut-map (obj-ary :a 1 :b 2 :c 3 :d 4))
{:a 1, :b 2, :c 3, :d 4}
ham-fisted.api> (type *1)
ham_fisted.PersistentArrayMap
ham-fisted.api> (immut-map (obj-ary :a 1 :b 2 :c 3 :d 4 :e 5))
{:d 4, :b 2, :c 3, :a 1, :e 5}
ham-fisted.api> (type *1)
ham_fisted.PersistentHashMap
ham-fisted.api> (immut-map [[:a 1][:b 2][:c 3][:d 4][:e 5]])
{:d 4, :b 2, :c 3, :a 1, :e 5}
ham-fisted.api> (type *1)
ham_fisted.PersistentHashMap
Create an immutable map. This object supports conversion to a transient map via Clojure's `transient` function. Duplicate keys are treated as if by assoc. If data is an object array it is treated as a flat key-value list which is distinctly different than how conj! treats object arrays. You have been warned. If you know you will have consistently more key/val pairs than 8 you should just use `(persistent! (mut-map data))` as that avoids the transition from an arraymap to a persistent hashmap. Options: * `:hash-provider` - An implementation of `BitmapTrieCommon$HashProvider`. Defaults to the [[default-hash-provider]]. Examples: ```clojure ham-fisted.api> (immut-map (obj-ary :a 1 :b 2 :c 3 :d 4)) {:a 1, :b 2, :c 3, :d 4} ham-fisted.api> (type *1) ham_fisted.PersistentArrayMap ham-fisted.api> (immut-map (obj-ary :a 1 :b 2 :c 3 :d 4 :e 5)) {:d 4, :b 2, :c 3, :a 1, :e 5} ham-fisted.api> (type *1) ham_fisted.PersistentHashMap ham-fisted.api> (immut-map [[:a 1][:b 2][:c 3][:d 4][:e 5]]) {:d 4, :b 2, :c 3, :a 1, :e 5} ham-fisted.api> (type *1) ham_fisted.PersistentHashMap ```
(immut-set)
(immut-set data)
(immut-set options data)
Create an immutable hashset based on the bitmap trie. This object supports conversion
to transients via transient
.
Options:
:hash-provider
- An implementation of BitmapTrieCommon$HashProvider
. Defaults to
the default-hash-provider
.Create an immutable hashset based on the bitmap trie. This object supports conversion to transients via `transient`. Options: * `:hash-provider` - An implementation of `BitmapTrieCommon$HashProvider`. Defaults to the [[default-hash-provider]].
(in-fork-join-task?)
True if you are currently running in a fork-join task
True if you are currently running in a fork-join task
(int-array data)
Create an integer array from a number of some data
Create an integer array from a number of some data
(int-array-list)
(int-array-list cap-or-data)
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
(intersection s1 s2)
Intersect the keyspace of set1 and set2 returning a new set. Also works if s1 is a map and s2 is a set - the map is trimmed to the intersecting keyspace of s1 and s2.
Intersect the keyspace of set1 and set2 returning a new set. Also works if s1 is a map and s2 is a set - the map is trimmed to the intersecting keyspace of s1 and s2.
(into container data)
(into container xform data)
Like clojure.core/into, but also designed to handle editable collections, transients, and base java.util.Map, List and Set containers.
Like clojure.core/into, but also designed to handle editable collections, transients, and base java.util.Map, List and Set containers.
(into-array aseq)
(into-array ary-type aseq)
(into-array ary-type mapfn aseq)
Faster version of clojure.core/into-array.
Faster version of clojure.core/into-array.
(iter-reduce rfn iter)
(iter-reduce rfn init iter)
Faster reduce for things like arraylists or hashmap entrysets that implement Iterable but not IReduceInit.
Faster reduce for things like arraylists or hashmap entrysets that implement Iterable but not IReduceInit.
(java-concurrent-hashmap)
(java-concurrent-hashmap data)
Create a java concurrent hashmap which is still the fastest possible way to solve a few concurrent problems.
Create a java concurrent hashmap which is still the fastest possible way to solve a few concurrent problems.
(java-hashmap)
(java-hashmap data)
Create a java.util.HashMap. Duplicate keys are treated as if map was created by assoc.
Create a java.util.HashMap. Duplicate keys are treated as if map was created by assoc.
(java-hashset)
(java-hashset data)
Create a java hashset which is still the fastest possible way to solve a few problems.
Create a java hashset which is still the fastest possible way to solve a few problems.
(larange end)
(larange start end)
(larange start end step)
Return a long array holding values of the range. Use ->collection
get a list
implementation for generic access.
Return a long array holding values of the range. Use `->collection` get a list implementation for generic access.
(last coll)
Get the last item in the collection. Constant time for random access lists.
Get the last item in the collection. Constant time for random access lists.
(long-array data)
Create a long array from a number of some data
Create a long array from a number of some data
(long-array-list)
(long-array-list cap-or-data)
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an array list.
(long-binary-operator lvar rvar & code)
Create a binary operator that is specialized for long values. Useful to speed up operations such as sorting or summation.
Create a binary operator that is specialized for long values. Useful to speed up operations such as sorting or summation.
(make-comparator lhsvar rhsvar code)
Make a java comparator.
Make a java comparator.
(make-double-comparator lhsvar rhsvar & code)
Make a comparator that gets passed two double arguments.
Make a comparator that gets passed two double arguments.
(make-long-comparator lhsvar rhsvar & code)
Make a comparator that gets passed two long arguments.
Make a comparator that gets passed two long arguments.
(map-factory keys)
Create a factory to quickly produce maps with a fixed set of keys but arbitrary values. This version takes a vector or sequence of keys and returns and IFn that takes a vector, object-array, or sequence of values. The most efficient pathway will be if values are already in an object array.
The factory produces PersistentHashMaps.
Create a factory to quickly produce maps with a fixed set of keys but arbitrary values. This version takes a vector or sequence of keys and returns and IFn that takes a vector, object-array, or sequence of values. The most efficient pathway will be if values are already in an object array. The factory produces PersistentHashMaps.
(map-intersection bfn map1 map2)
Intersect the keyspace of map1 and map2 returning a new map. Each value is the result
of bfn applied to the map1-value and map2-value, respectively. See documentation for
map-union
.
Clojure's merge
functionality can be duplicate via:
(map-intersection (fn [lhs rhs] rhs) map1 map2)
Intersect the keyspace of map1 and map2 returning a new map. Each value is the result of bfn applied to the map1-value and map2-value, respectively. See documentation for [[map-union]]. Clojure's `merge` functionality can be duplicate via: ```clojure (map-intersection (fn [lhs rhs] rhs) map1 map2) ```
(map-keyset m)
Return the keyset of the map. This may not be in the same order as (keys m) or (vals m). For hamf maps, this has the same ordering as (keys m). For both hamf and java hashmaps, the returned implementation of java.util.Set both more utility and better performance than (keys m).
Return the keyset of the map. This may not be in the same order as (keys m) or (vals m). For hamf maps, this has the same ordering as (keys m). For both hamf and java hashmaps, the returned implementation of java.util.Set both more utility and better performance than (keys m).
(map-union bfn map1 map2)
Take the union of two maps returning a new map. bfn is a function that takes 2 arguments, map1-val and map2-val and returns a new value. Has fallback if map1 and map2 aren't backed by bitmap tries.
bfn
- A function taking two arguments and returning one. +
is a fine choice.map1
- the lhs of the union.map2
- the rhs of the union.Returns a persistent map.
Take the union of two maps returning a new map. bfn is a function that takes 2 arguments, map1-val and map2-val and returns a new value. Has fallback if map1 and map2 aren't backed by bitmap tries. * `bfn` - A function taking two arguments and returning one. `+` is a fine choice. * `map1` - the lhs of the union. * `map2` - the rhs of the union. Returns a persistent map.
(map-union-java-hashmap bfn lhs rhs)
Take the union of two maps returning a new map. See documentation for [map-union]. Returns a java.util.HashMap.
Take the union of two maps returning a new map. See documentation for [map-union]. Returns a java.util.HashMap.
(map-values m)
Return the values collection of the map. This may not be in the same order as (keys m)
or (vals m). For hamf hashmaps, this does have the same order as (vals m). For both
hamf hashmaps and java hashmaps, this has better performance for reductions especially
using fast-reduce
than (vals m).
Return the values collection of the map. This may not be in the same order as (keys m) or (vals m). For hamf hashmaps, this does have the same order as (vals m). For both hamf hashmaps and java hashmaps, this has better performance for reductions especially using `fast-reduce` than (vals m).
(mapmap map-fn src-map)
Clojure's missing piece. Map over the data in src-map, which must be a map or sequence of pairs, using map-fn. map-fn must return either a new key-value pair or nil. Then, remove nil pairs, and return a new map. If map-fn returns more than one pair with the same key later pair will overwrite the earlier pair.
Logically the same as:
(->> (map map-fn src-map) (remove nil?) (into {}))
Clojure's missing piece. Map over the data in src-map, which must be a map or sequence of pairs, using map-fn. map-fn must return either a new key-value pair or nil. Then, remove nil pairs, and return a new map. If map-fn returns more than one pair with the same key later pair will overwrite the earlier pair. Logically the same as: ```clojure (->> (map map-fn src-map) (remove nil?) (into {})) ```
(mapv map-fn coll)
Produce a persistent vector from a collection
Produce a persistent vector from a collection
(mean coll)
Return the mean of the collection. Returns double/NaN for empty collections.
Return the mean of the collection. Returns double/NaN for empty collections.
(memoize memo-fn)
(memoize memo-fn
{:keys [write-ttl-ms access-ttl-ms soft-values? weak-values? max-size
record-stats?]})
Efficient thread-safe version of clojure.core/memoize.
Also see clear-memoized-fn!
to mutably clear the backing store.
Options.
:write-ttl-ms
- Time that values should remain in the cache after write in milliseconds.:access-ttl-ms
- Time that values should remain in the cache after access in milliseconds.:soft-values?
- When true, the cache will store SoftReferences to the data.:weak-values?
- When true, the cache will store WeakReferences to the data.:max-size
- When set, the cache will behave like an LRU cache.:record-stats?
- When true, the LoadingCache will record access statistics. You can
get those via the undocumented function memo-stats.Efficient thread-safe version of clojure.core/memoize. Also see [[clear-memoized-fn!]] to mutably clear the backing store. Options. * `:write-ttl-ms` - Time that values should remain in the cache after write in milliseconds. * `:access-ttl-ms` - Time that values should remain in the cache after access in milliseconds. * `:soft-values?` - When true, the cache will store [SoftReferences](https://docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html) to the data. * `:weak-values?` - When true, the cache will store [WeakReferences](https://docs.oracle.com/javase/7/docs/api/java/lang/ref/WeakReference.html) to the data. * `:max-size` - When set, the cache will behave like an LRU cache. * `:record-stats?` - When true, the LoadingCache will record access statistics. You can get those via the undocumented function memo-stats.
(merge)
(merge m1)
(merge m1 m2)
(merge m1 m2 & args)
Merge 2 maps with the rhs values winning any intersecting keys. Uses map-union
with BitmapTrieCommon/rhsWins
.
Returns a new persistent map.
Merge 2 maps with the rhs values winning any intersecting keys. Uses map-union with `BitmapTrieCommon/rhsWins`. Returns a new persistent map.
(merge-with f)
(merge-with f m1)
(merge-with f m1 m2)
(merge-with f m1 m2 & args)
Merge (union) any number of maps using f
as the merge operator. f
gets passed two
arguments, lhs-val and rhs-val and must return a new value.
Returns a new persistent map.
Merge (union) any number of maps using `f` as the merge operator. `f` gets passed two arguments, lhs-val and rhs-val and must return a new value. Returns a new persistent map.
(mut-list)
(mut-list data)
Create a mutable java list that is in-place convertible to a persistent list
Create a mutable java list that is in-place convertible to a persistent list
(mut-map)
(mut-map data)
(mut-map options data)
Create a mutable implementation of java.util.Map. This object efficiently implements
ITransient map so you can use assoc! and persistent! on it but you can additionally use
operations such as put!, remove!, compute-at! and compute-if-absent!. You can create
a persistent hashmap via the clojure persistent!
call.
If data is an object array it is treated as a flat key-value list which is distinctly different than how conj! treats object arrays. You have been warned.
Options:
:hash-provider
- An implementation of BitmapTrieCommon$HashProvider
. Defaults to
the default-hash-provider
.Create a mutable implementation of java.util.Map. This object efficiently implements ITransient map so you can use assoc! and persistent! on it but you can additionally use operations such as put!, remove!, compute-at! and compute-if-absent!. You can create a persistent hashmap via the clojure `persistent!` call. If data is an object array it is treated as a flat key-value list which is distinctly different than how conj! treats object arrays. You have been warned. Options: * `:hash-provider` - An implementation of `BitmapTrieCommon$HashProvider`. Defaults to the [[default-hash-provider]].
(mut-set)
(mut-set data)
(mut-set options data)
Create a mutable hashset based on the bitmap trie. You can create a persistent hashset via
the clojure persistent!
call.
Options:
:hash-provider
- An implementation of BitmapTrieCommon$HashProvider
. Defaults to
the default-hash-provider
.Create a mutable hashset based on the bitmap trie. You can create a persistent hashset via the clojure `persistent!` call. Options: * `:hash-provider` - An implementation of `BitmapTrieCommon$HashProvider`. Defaults to the [[default-hash-provider]].
(obj-ary)
(obj-ary v0)
(obj-ary v0 v1)
(obj-ary v0 v1 v2)
(obj-ary v0 v1 v2 v3)
(obj-ary v0 v1 v2 v3 v4)
(obj-ary v0 v1 v2 v3 v4 v5)
(obj-ary v0 v1 v2 v3 v4 v5 v6)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14)
(obj-ary v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15)
As quickly as possible, produce an object array from these inputs. Very fast for arities <= 6.
As quickly as possible, produce an object array from these inputs. Very fast for arities <= 6.
(object-array item)
Faster version of object-array for java collections and strings.
Faster version of object-array for java collections and strings.
(object-array-list)
(object-array-list cap-or-data)
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an object array based list.
An array list that is as fast as java.util.ArrayList for add,get, etc but includes many accelerated operations such as fill and an accelerated addAll when the src data is an object array based list.
(pgroups n-elems body-fn)
(pgroups n-elems body-fn options)
Run y groups across n-elems. Y is common pool parallelism.
body-fn gets passed two longs, startidx and endidx.
Returns a sequence of the results of body-fn applied to each group of indexes.
Options:
:pgroup-min
- when provided n-elems must be more than this value for the computation
to be parallelized.:batch-size
- max batch size. Defaults to 64000.Run y groups across n-elems. Y is common pool parallelism. body-fn gets passed two longs, startidx and endidx. Returns a sequence of the results of body-fn applied to each group of indexes. Options: * `:pgroup-min` - when provided n-elems must be more than this value for the computation to be parallelized. * `:batch-size` - max batch size. Defaults to 64000.
(pmap map-fn & sequences)
pmap using the commonPool. This is useful for interacting with other primitives, namely
pgroups
which are also based on this pool. This is a change from Clojure's base
pmap in that it uses the ForkJoinPool/commonPool for parallelism as opposed to the
agent pool - this makes it compose with pgroups and dtype-next's parallelism system.
pmap using the commonPool. This is useful for interacting with other primitives, namely [[pgroups]] which are also based on this pool. This is a change from Clojure's base pmap in that it uses the ForkJoinPool/commonPool for parallelism as opposed to the agent pool - this makes it compose with pgroups and dtype-next's parallelism system.
(range)
(range end)
(range start end)
(range start end step)
When given arguments returns a range that implements random access java list interfaces so nth, reverse and friends are efficient.
When given arguments returns a range that implements random access java list interfaces so nth, reverse and friends are efficient.
A reverse comparator that sorts in descending order
A reverse comparator that sorts in descending order
(reduce-put-map m data)
Perform a reduction to put values as if by assoc into a mutable map.
Perform a reduction to put values as if by assoc into a mutable map.
(reindex coll indexes)
Permut coll by the given indexes. Result is random-access and the same length as the index collection. Indexes are expected to be in the range of [0->count(coll)).
Permut coll by the given indexes. Result is random-access and the same length as the index collection. Indexes are expected to be in the range of [0->count(coll)).
(repeat v)
(repeat n v)
When called with no arguments, produce an infinite sequence of v. When called with 2 arguments, produce a random access list that produces v at each index.
When called with no arguments, produce an infinite sequence of v. When called with 2 arguments, produce a random access list that produces v at each index.
(reverse coll)
Reverse a collection or sequence. Constant time reverse is provided for any random access list.
Reverse a collection or sequence. Constant time reverse is provided for any random access list.
(shuffle coll)
(shuffle coll opts)
shuffle values returning random access container.
Options:
:seed
- If instance of java.util.Random, use this. If integer, use as seed.
If not provided a new instance of java.util.Random is created.shuffle values returning random access container. Options: * `:seed` - If instance of java.util.Random, use this. If integer, use as seed. If not provided a new instance of java.util.Random is created.
(sort coll)
(sort comp coll)
Exact replica of clojure.core/sort but instead of wrapping the final object array in a seq which loses the fact the result is countable and random access. Faster implementations are provided when the input is an integer, long, or double array.
Exact replica of clojure.core/sort but instead of wrapping the final object array in a seq which loses the fact the result is countable and random access. Faster implementations are provided when the input is an integer, long, or double array.
(sort-by keyfn coll)
(sort-by keyfn comp coll)
Sort a collection by keyfn. Typehinting the return value of keyfn will somewhat increase the speed of the sort :-).
Sort a collection by keyfn. Typehinting the return value of keyfn will somewhat increase the speed of the sort :-).
(sorta coll)
(sorta comp coll)
Sort returning an object array.
Sort returning an object array.
(splice v1 idx v2)
Splice v2 into v1 at idx. Returns a persistent vector.
Splice v2 into v1 at idx. Returns a persistent vector.
(subvec m sidx)
(subvec m sidx eidx)
More general version of subvec. Works for any java list implementation including persistent vectors and any array.
More general version of subvec. Works for any java list implementation including persistent vectors and any array.
(sum coll)
Fast simple double summation. Does not do any summation compensation but does parallelize the summation for random access containers leading to some additional numeric stability.
Fast simple double summation. Does not do any summation compensation but does parallelize the summation for random access containers leading to some additional numeric stability.
(take n coll)
Take the first N values from a collection. If the input is random access, the result will be random access.
Take the first N values from a collection. If the input is random access, the result will be random access.
(take-last n coll)
Take the last N values of the collection. If the input is random-access, the result will be random-access.
Take the last N values of the collection. If the input is random-access, the result will be random-access.
(take-min n values)
(take-min n comp values)
Take the min n values of a collection. This is not an order-preserving operation.
Take the min n values of a collection. This is not an order-preserving operation.
(type-single-arg-ifn ifn)
Categorize the return type of a single argument ifn. May be :float64, :int64, or :object.
Categorize the return type of a single argument ifn. May be :float64, :int64, or :object.
(union s1 s2)
Union of two sets or two maps. When two maps are provided the right hand side wins in the case of an intersection.
Result is either a set or a map, depending on if s1 is a set or map.
Union of two sets or two maps. When two maps are provided the right hand side wins in the case of an intersection. Result is either a set or a map, depending on if s1 is a set or map.
(union-reduce-java-hashmap bfn maps)
(union-reduce-java-hashmap bfn maps options)
Do an efficient union of many maps into a single java.util.HashMap.
Do an efficient union of many maps into a single java.util.HashMap.
(union-reduce-maps bfn maps)
Do an efficient union reduction across many maps using bfn to update values. See
documentation for [map-union]. If any of the input maps are not implementations provided
by this library this falls backs to (reduce (partial union-maps bfn) maps)
.
Do an efficient union reduction across many maps using bfn to update values. See documentation for [map-union]. If any of the input maps are not implementations provided by this library this falls backs to `(reduce (partial union-maps bfn) maps)`.
(update m k f)
(update m k f x)
(update m k f x y)
(update m k f x y z)
(update m k f x y z & more)
Version of update that produces maps from this library.
Version of update that produces maps from this library.
(update-in m ks f & args)
An attempt at a slightly more efficient version of update-in.
See the caveats in the readme - measure carefully before using this.
An attempt at a slightly more efficient version of update-in. See the caveats in the readme - measure carefully before using this.
(update-values map bfn)
Immutably update all values in the map returning a new map. bfn takes 2 arguments, k,v and returns a new v. Returns new persistent map. If passed a vector, k is the index and v is the value. Will return a new vector. else map is assumed to be convertible to a sequence and this pathway works the same as map-indexed.
Immutably update all values in the map returning a new map. bfn takes 2 arguments, k,v and returns a new v. Returns new persistent map. If passed a vector, k is the index and v is the value. Will return a new vector. else map is assumed to be convertible to a sequence and this pathway works the same as map-indexed.
(upmap map-fn & sequences)
Unordered pmap using the commonPool. This is useful for interacting with other primitives,
namely pgroups
which are also based on this pool.
Like pmap this uses the commonPool so it composes with this api's pmap, pgroups, and
dtype-next's parallelism primitives but it does not impose an ordering constraint on the
results and thus may be significantly faster in some cases.
Unordered pmap using the commonPool. This is useful for interacting with other primitives, namely [[pgroups]] which are also based on this pool. Like pmap this uses the commonPool so it composes with this api's pmap, pgroups, and dtype-next's parallelism primitives *but* it does not impose an ordering constraint on the results and thus may be significantly faster in some cases.
(vec data)
Produce a persistent vector. Optimized pathways exist for object arrays and java List implementations.
Produce a persistent vector. Optimized pathways exist for object arrays and java List implementations.
(vector)
(vector a)
(vector a b)
(vector a b c)
(vector a b c d)
(vector a b c d e)
(vector a b c d e f)
(vector a b c d e f g)
(vector a b c d e f g h)
(vector a b c d e f g h i)
(vector a b c d e f g h i j)
(vector a b c d e f g h i j k)
(vector a b c d e f g h i j k & args)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close