slices +linux +x86_64

The slices module provides some utility functions for working with slices. In order to work with a user-supplied slice of an arbitrary type, the slice must be cast to []void and the size of the member type passed alongside it. These functions provide support code for common operations such as indexing and appending, which are normally provided by language features, but which are not available for []void slices.

Index

Functions

fn appendto(*[]void, size, const *void...) void;
fn cap([]const void) size;
fn deletefrom(*[]void, size, size, size) void;
fn index([]void, size, size) *void;
fn insertinto(*[]void, size, size, const *void...) void;
fn reverse([]void, size) void;
fn static_appendto(*[]void, size, const *void...) void;
fn static_deletefrom(*[]void, size, size, size) void;
fn static_insertinto(*[]void, size, size, const *void...) void;
fn swap([]void, size, size, size) void;
fn trunc(*[]void) void;

Functions

fn appendto[link]

fn appendto(sl: *[]void, itemsz: size, items: const *void...) void;

Appends an item, or multiple items, to a slice, reallocating if necessary.

fn cap[link]

fn cap(slice: []const void) size;

Returns the capacity of a slice.

fn deletefrom[link]

fn deletefrom(sl: *[]void, itemsz: size, start: size, end: size) void;

Deletes a range of items from a slice, in O(n) time. The slice may be reallocated. Reallocation will never fail.

fn index[link]

fn index(sl: []void, itemsz: size, n: size) *void;

Returns a pointer to the nth item of a slice.

fn insertinto[link]

fn insertinto(sl: *[]void, itemsz: size, idx: size, items: const *void...) void;

Inserts an item, or multiple items, to a slice, in O(n) time, reallocating if necessary.

fn reverse[link]

fn reverse(b: []void, membsz: size) void;

Reverses a slice.

fn static_appendto[link]

fn static_appendto(sl: *[]void, itemsz: size, items: const *void...) void;

Appends an item, or multiple items, to a slice. Aborts if the slice's capacity isn't large enough to fit the items.

fn static_deletefrom[link]

fn static_deletefrom(sl: *[]void, itemsz: size, start: size, end: size) void;

Deletes a range of items from a slice, in O(n) time, without freeing memory.

fn static_insertinto[link]

fn static_insertinto(sl: *[]void, itemsz: size, idx: size, items: const *void...) void;

Inserts an item, or multiple items, into a slice, in O(n) time. Aborts if the slice's capacity isn't large enough to fit the items.

fn swap[link]

fn swap(sl: []void, itemsz: size, a: size, b: size) void;

Swaps two elements of a slice.

fn trunc[link]

fn trunc(sl: *[]void) void;

Truncates a slice, setting its length to zero without freeing the underlying storage or altering its capacity.