pub struct Zuffer { /* private fields */ }
Expand description

Zuffer is equivalent of Go’s bytes.Zuffer without the ability to read. It is NOT thread-safe.

In Memory mode, default allocator is used to allocate memory, which depending upon how the code is compiled could use jemalloc for allocations.

In Mmap mode, Zuffer uses file mmap to allocate memory. This allows us to store big data structures without using physical memory.

max_size can be set to limit the memory usage.

Implementations

default capacity of the buffer

Returns a memory buffer with default capacity

NOTE:

It is the caller’s responsibility to set offset after this, because Zuffer doesn’t remember what it was.

Returns a persistent buffer with default capacity

NOTE:

It is the caller’s responsibility to set offset after this, because Zuffer doesn’t remember what it was.

Returns a temperary buffer with default capacity, the underlying temp file will be removed when the struct is dropped.

NOTE:

It is the caller’s responsibility to set offset after this, because Zuffer doesn’t remember what it was.

Returns a memory buffer with default capacity, but after the size exceeds the threshold, then the buffer will auto mmap to a temp file.

NOTE:

It is the caller’s responsibility to set offset after this, because Zuffer doesn’t remember what it was.

Set the maximum size for the buffer.

Returns if the buffer is empty

Returns the buffer start offset

Returns the tag of the buffer

Set the tag for the buffer

Returns the number of bytes written to the buffer so far plus the padding at the start of the buffer.

Returns the number of bytes written to the buffer so far (without the padding).

Returns all the written bytes as a slice

Returns all the written bytes as a mutable slice

Returns the underlying data in range [offset..current_size - offset]

Returns the mutable underlying data in range [offset..current_size - offset]

Grow would grow the buffer to have at least n more bytes. In case the buffer is at capacity, it would reallocate twice the size of current capacity + n, to ensure n bytes can be written to the buffer without further allocation. In UseMmap mode, this might result in underlying file expansion.

allocate is a way to get a slice of size n back from the buffer. This slice can be directly written to.

Warning:

Allocate is not thread-safe. The byte slice returned MUST be used before further calls to Zuffer.

allocate_offset works the same way as allocate, but instead of returning a byte slice, it returns the offset of the allocation.

slice_allocate would encode the size provided into the buffer, followed by a call to allocate, hence returning the slice of size sz. This can be used to allocate a lot of small buffers into this big buffer. Note that slice_allocate should NOT be mixed with normal calls to write.

write would write p bytes to the buffer.

Write all bytes to the buffer

reset would reset the buffer to be reused.

slice would return the slice written at offset.

slice_mut would return the slice written at offset.

slice_offsets is an expensive function. Use sparingly.

Iterates over the buffer

Iterates over the buffer

Sort the buffer

Sort the buffer between the given offsets

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Item
Slice sorts the slice x given the provided less function. Read more
Sorts the slice data using the provided less function, keeping equal elements in their original order. Read more
Returns whether the slice x is sorted according to the provided less function.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.