create vector bs
Definition
vector_t *create_vector_bs(unsigned int buffer, compare_vector_value_t compare_func);
Description
Allocates memory for the vector structure with sorted elements and a custom buffer. It isn't sorted just by calling a function like vector_sort(vector). Instead it will find the correct position when a new element is pushed.
Parameters
- buffer
- Size of the buffer.
- compare_func
- Function to compare 2 elements.
Return Value
Allocated vector_t structure.
Example
#include <stdio.h> #include <libc/vector.h> signed char compare_double_value(void *ptr1, void *ptr2) { if(*((double *)ptr1) < *((double *)ptr2)) { return VECTOR_COMPARE_LESS; } else if(*((double *)ptr1) == *((double *)ptr2)) { return VECTOR_COMPARE_EQUAL; } else { return VECTOR_COMPARE_MORE; } } int main(int argc, char *argv[]) { // create a vector with double elements sorting vector_t *vector = create_vector_bs(100, compare_double_value); destroy_vector(vector); return 0; }