Unsynchronized mutable collections with predefined capacity.

Buffers are very fast FIFO mutable collections which have their fixed capacity set at the creation time. They support following functionalities:

  • peek for getting the first inserted value.

  • conj! for inserting new values and pop! for removal of first inserted value.

  • empty?, full?, brimming?, capacity and count for querying the capacity and the number of items.

  • clone for safe cloning.

  • settle! for settling down the collection (converting to the immutable variant).

Buffers follow usual mutable semantics, i.e. you should always use a value returned from a mutable function instead of using the old passed-in value.

Individual buffer types differ in the way they behave when there is no more space for a new item.

There are no synchronization guarantees for buffer types, use them with care!

buffer

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (buffer n)

  • (buffer type n)

Type signatures:
  • (Int) → IMutableCollection

  • ((U nil Keyword Class Type) ⨯ Int) → IMutableCollection

Returns a fixed buffer of a size n. Optional type may be provided for buffers holding primitive values. conj! to the fixed buffer throws if there is no more space for new items.

dropping-buffer

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (dropping-buffer n)

  • (dropping-buffer type n)

Type signatures:
  • (Int) → IMutableCollection

  • ((U nil Keyword Class Type) ⨯ Int) → IMutableCollection

Returns a dropping buffer of a size n. Optional type may be provided for buffers holding primitive values. conj! to the dropping buffer silently drops new items if there is no space for them (not yet inserted items will be dropped and buffer will remain the same).

port-buffer?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (port-buffer? x)

Type signature: Predicate

Returns true if object x satisfies IPortBuffer protocol, false otherwise.

See also: IPortBuffer

sliding-buffer

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (sliding-buffer n)

  • (sliding-buffer type n)

Type signatures:
  • (Int) → IMutableCollection

  • ((U nil Keyword Class Type) ⨯ Int) → IMutableCollection

Returns a sliding buffer of a size n. Optional type may be provided for buffers holding primitive values. conj! to the sliding buffer silently drops oldest items if there is no space for them (new items will be inserted and oldest will be dropped).

stretching-buffer

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (stretching-buffer n)

  • (stretching-buffer type n)

Type signatures:
  • (Int) → IMutableCollection

  • ((U nil Keyword Class Type) ⨯ Int) → IMutableCollection

Returns a stretching buffer of a size n. Optional type may be provided for buffers holding primitive values. While stretching buffer presents itself as a buffer of fixed length, conj! to the stretching buffer is always accepted and internal buffer size is enlarged if needed, while presented capacity remains.

Is useful for channels, where transducer may produce multiple values from one input value.