Skip to content

SRNissen/slice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lib snns_Slice

Convenience functions for a C byte slice

    typedef struct snns_Slice
    {
        void *arr;
        size_t cap;
    } snns_Slice;

Testing

The script make_and_test.sh compiles with address- and memory-sanitizer and runs through the tests specified in test.c

Functions

All functions are described in more detail in snns_slice.h

    //Returns an initialized slice
    snns_Slice snns_Slice_makeNew(void); 
    //Initialized an existing slice
    void snns_Slice_doInit(snns_Slice*);
    //Tests if a slice is initialized
    bool snns_Slice_isInit(snns_Slice*);
    //Sets all allocated bytes to zero
    void snns_Slice_doClear(snns_Slice*);
    //Tests if all allocated bytes are zero
    bool snns_Slice_isClear_linearN(snns_Slice*);
    //Allocates a zeroed out array of bytes to the slice
    snns_Slice_Result snns_Slice_calloc(snns_Slice*, size_t);
    //Re-allocates a slice if it is shorter than requested
    snns_Slice_Result snns_Slice_calloc(snns_Slice*, size_t);
    //Deallocates a slice and sets it to the Init state
    void snns_Slice_dealloc(snns_Slice*);
    //Overwrites content of first slice with content of second slice
    snns_Slice_Result snns_Slice_copy(snns_Slice*, snns_Slice*);
    //Appends content of second slice to first slice
    snns_Slice_Result snns_Slice_append(snns_Slice*, snns_Slice*);

About

A Slice implementation for C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published