Liking cljdoc? Tell your friends :D

uncomplicate.commons.utils

Assorted utility functions used across Uncomplicate projects.

For converting keyword options to integers, use mask, unmask, and unmask1.

For converting C-style error as returned numbers to exceptions, use with-check and dragan-says-ex.

A few assorted functions: enc-keyword, cond-into.

When working with ByteBuffers, enlist the following functions for help: direct-buffer, slice-buffer, capacity, put-float! get-float put-double! get-double put-long! get-long put-int! get-int put-short! get-short put-byte! get-byte

When mapping files to direct buffers, these functions can help. mapped-buffer, reverse-short-bytes!, reverse-long-bytes!

The following functions are useful when working with Java file channels. [[dev-open-option]], channel random-access

Sometimes we need a pseudo-random number for kick-starting a random number generator. generate-secure-seed, generate-seed

And we may need to count groups of items in a larger group. count-groups

Assorted utility functions used across Uncomplicate projects.

For converting keyword options to integers, use [[mask]], [[unmask]], and [[unmask1]].

For converting C-style error as returned numbers to exceptions, use [[with-check]] and
[[dragan-says-ex]].

A few assorted functions: [[enc-keyword]], [[cond-into]].

When working with `ByteBuffers`, enlist the following functions for help:
[[direct-buffer]], [[slice-buffer]], [[capacity]],
[[put-float!]] [[get-float]] [[put-double!]] [[get-double]] [[put-long!]] [[get-long]]
[[put-int!]] [[get-int]] [[put-short!]] [[get-short]] [[put-byte!]] [[get-byte]]

When mapping files to direct buffers, these functions can help.
[[mapped-buffer]], [[reverse-short-bytes!]], [[reverse-long-bytes!]]

The following functions are useful when working with Java file channels.
[[dev-open-option]], [[channel]] [[random-access]]

Sometimes we need a pseudo-random number for kick-starting a random number generator.
[[generate-secure-seed]], [[generate-seed]]

And we may need to count groups of items in a larger group.
[[count-groups]]
raw docstring

capacityclj

(capacity b)

Returns the capacity of a byte buffer.

Returns the capacity of a byte buffer.
sourceraw docstring

channelclj

(channel file)
(channel p options)

Creates a file channel

Creates a file channel
sourceraw docstring

cond-intoclj

(cond-into x & s)

Puts all even arguments into collection x, given that the previous argument was not nil or false.

Puts all even arguments into collection `x`, given that the previous argument was not nil or false.
sourceraw docstring

count-groupsclj

(count-groups per-group items)

Calculates the number of groups of certain size in the total number of items.

Calculates the number of groups of certain size in the total number of items.
sourceraw docstring

create-temp-dirclj

(create-temp-dir prefix)

Creates a temp directory appropriate for the operating system, prefixed with 'uncomplicate_.

Creates a temp directory appropriate for the operating system, prefixed with 'uncomplicate_.
sourceraw docstring

dec-open-optionclj

(dec-open-option option)

Decode keywords to StandardOpenOption's

Decode keywords to `StandardOpenOption`'s
sourceraw docstring

deleteclj

(delete path)

Deletes the path, if it exists.

Deletes the path, if it exists.
sourceraw docstring

direct-bufferclj

(direct-buffer size)

Allocates a direct buffer with native byte order.

Allocates a direct buffer with native byte order.
sourceraw docstring

dragan-says-exclj

(dragan-says-ex message)
(dragan-says-ex message data)

Throws and ex-info with an explanation and a tip towards a solution.

Throws and `ex-info` with an explanation and a tip towards a solution.
sourceraw docstring

enc-keywordclj

(enc-keyword kw-map kw)

Given a hash-map and a key, returns the appropriate value, or throws an exception with the listing of available keys.

Given a hash-map and a key, returns the appropriate value, or throws an exception
with the listing of available keys.
sourceraw docstring

generate-secure-seedclj

(generate-secure-seed)

Generates a secure seed. This pseudo-random number is random more than enough for almost all purposes Uncomplicate projects deal with, but it is often slow to generate as we have to wait for the operating systems to do the rain dance to acquire it. For most simulation work, it is much better to use generate-seed, which returns fairly good pseudo-random numbers that are further used as seeds of pseudo-random number generators.

Generates a secure seed. This pseudo-random number is `random more than enough` for almost all
purposes Uncomplicate projects deal with, but it is often slow to generate as we have to wait for
the operating systems to do the rain dance to acquire it. For most simulation work, it is much
better to use [[generate-seed]], which returns fairly good pseudo-random numbers that are further
used as seeds of pseudo-random number generators.
sourceraw docstring

generate-seedclj

(generate-seed)

Generates a pseudo-random seed for jump-starting pseudo-random generators. Random enough for most simulation algorithms that we use in Uncomplicate, and very cheap to acquire.

Generates a pseudo-random seed for jump-starting pseudo-random generators. Random enough for most
simulation algorithms that we use in Uncomplicate, and very cheap to acquire.
sourceraw docstring

get-byteclj

(get-byte b i)

Gets a byte value at position i in a byte buffer.

Gets a byte value at position `i` in a byte buffer.
sourceraw docstring

get-doubleclj

(get-double b i)

Gets a double value at position i in a byte buffer.

Gets a double value at position `i` in a byte buffer.
sourceraw docstring

get-floatclj

(get-float b i)

Gets a float value at position i in a byte buffer.

Gets a float value at position `i` in a byte buffer.
sourceraw docstring

get-intclj

(get-int b i)

Gets an int value at position i in a byte buffer.

Gets an int value at position `i` in a byte buffer.
sourceraw docstring

get-longclj

(get-long b i)

Gets a long value at position i in a byte buffer.

Gets a long value at position `i` in a byte buffer.
sourceraw docstring

get-shortclj

(get-short b i)

Gets a short value at position i in a byte buffer.

Gets a short value at position `i` in a byte buffer.
sourceraw docstring

mapped-bufferclj

(mapped-buffer channel)
(mapped-buffer channel size-or-flag)
(mapped-buffer channel size flag)
(mapped-buffer channel offset size flag)

Returns a ByteBuffer mapped to a FileChannel of given size, from offset.

Returns a `ByteBuffer` mapped to a `FileChannel` of given `size`, from `offset`.
sourceraw docstring

maskclj

(mask table flags)
(mask table flag flags)
(mask table flag1 flag2 flags)

Converts keywords to a bitfield mask.

Given one or more keyword flags, creates a long bitmask that can be consumed by native functions. Needs a hashmap table that contains possible long mappings, 0-2 keywords, and a (possibly empty) list of additional keywords. If called with nil table or an unknown keyword, throws Illegalargumentexception. The inverse function is unmask.

Examples:

(mask {:a 1 :b 2 :c 4} [:a :c]) => 5
(mask {:a 1 :b 2 :c 4} :a [:c]) => 5
(mask {:a 1 :b 2 :c 4} :a :c []) => 5
Converts keywords to a bitfield mask.

Given one or more keyword `flag`s, creates a long bitmask
that can be consumed by native functions. Needs a hashmap `table` that
contains possible long mappings, 0-2 keywords, and a (possibly empty)
list of additional keywords.
If called with `nil` table or an unknown keyword, throws `Illegalargumentexception`.
The inverse function is [[unmask]].

Examples:

    (mask {:a 1 :b 2 :c 4} [:a :c]) => 5
    (mask {:a 1 :b 2 :c 4} :a [:c]) => 5
    (mask {:a 1 :b 2 :c 4} :a :c []) => 5
sourceraw docstring

pathclj

(path path-name file-name & file-names)

Builds Java Path from the appropriate path name and file names.

Builds Java Path from the appropriate path name and file names.
sourceraw docstring

put-byte!clj

(put-byte! b i x)

Puts a byte into a byte buffer, at position i.

Puts a byte into a byte buffer, at position `i`.
sourceraw docstring

put-double!clj

(put-double! b i x)

Puts a double into a byte buffer, at position i.

Puts a double into a byte buffer, at position `i`.
sourceraw docstring

put-float!clj

(put-float! b i x)

Puts a float into a byte buffer, at position i.

Puts a float into a byte buffer, at position `i`.
sourceraw docstring

put-int!clj

(put-int! b i x)

Puts an int into a byte buffer, at position i.

Puts an int into a byte buffer, at position `i`.
sourceraw docstring

put-long!clj

(put-long! b i x)

Puts a long into a byte buffer, at position i.

Puts a long into a byte buffer, at position `i`.
sourceraw docstring

put-short!clj

(put-short! b i x)

Puts a short into a byte buffer, at position i.

Puts a short into a byte buffer, at position `i`.
sourceraw docstring

random-accessclj

(random-access path)
(random-access path flag)

Creates a random access file.

Creates a random access file.
sourceraw docstring

reverse-int-bytes!clj

(reverse-int-bytes! buffer!)

Reverses bytes in integer numbers in a given ByteBuffer

Reverses bytes in integer numbers in a given `ByteBuffer`
sourceraw docstring

reverse-long-bytes!clj

(reverse-long-bytes! buffer!)

Reverses bytes in long numbers in a given ByteBuffer

Reverses bytes in long numbers in a given `ByteBuffer`
sourceraw docstring

reverse-short-bytes!clj

(reverse-short-bytes! buffer!)

Reverses bytes in short numbers in a given ByteBuffer

Reverses bytes in short numbers in a given `ByteBuffer`
sourceraw docstring

slice-bufferclj

(slice-buffer buf ofst len)

Slices a buffer from offset with the given length.

Slices a buffer from offset with the given length.
sourceraw docstring

unmaskclj

(unmask table mask)

Converts a bitfield mask to keywords.

Given a mapping table and a bitfield mask, returns a lazy sequence with decoded keyword flags contained in the bitmask. The reverse function is mask.

Examples:

(unmask {:a 1 :b 2 :c 4} 5) =>  '(:a :c)
Converts a bitfield `mask` to keywords.

Given a mapping `table` and a bitfield `mask`, returns a lazy sequence
with decoded keyword flags contained in the bitmask.
The reverse function is [[mask]].

Examples:

    (unmask {:a 1 :b 2 :c 4} 5) =>  '(:a :c)
sourceraw docstring

unmask1clj

(unmask1 table mask)

Converts a bitfield mask to one keyword.

Given a mapping table and a bitfield mask, returns the first decoded keyword that is contained in the bitmask. This is useful when we know that just one of the values in the table fits the bitmask, so the result of unmask would contain one element anyway. The reverse function is mask.

Examples:

(unmask1 {:a 1 :b 2 :c 4} 2) => :b
Converts a bitfield `mask` to one keyword.

Given a mapping `table` and a bitfield `mask`, returns the first decoded keyword
that is contained in the bitmask. This is useful when we know that just
one of the values in the table fits the bitmask, so the result of [[unmask]]
would contain one element anyway.
The reverse function is [[mask]].

Examples:

    (unmask1 {:a 1 :b 2 :c 4} 2) => :b
sourceraw docstring

with-checkcljmacro

(with-check error-fn status form)

Evaluates form if status is zero (e.g. CL_SUCCESS), otherwise throws an appropriate ExceptionInfo with decoded informative details. It helps with native interop methods that return error codes directly, while returning computation results through side-effects in arguments.

Example:

(with-check (some-call-that-returns-error-code) result)
Evaluates `form` if `status` is zero (e.g. `CL_SUCCESS`), otherwise throws
an appropriate `ExceptionInfo` with decoded informative details.
It helps with native interop methods that return error codes directly, while
returning computation results through side-effects in arguments.

Example:

    (with-check (some-call-that-returns-error-code) result)
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close