|
mdz_vector Overview and Reference
mdz_vector - very lightweight, versatile and speedy C vector library. Source code of library is highly-portable, conforms to ANSI C 89/90 Standard.
Builds for Win32/Win64, Linux, FreeBSD, Android, macOS are available. Please refer to mdz_vector Wiki for API details.
mdz_vector Advantages
1. Very high portability: the whole code conforms to ANSI C 89/90 Standard. Multithreading/asynchronous part is POSIX compatible (under UNIX/Linux).
2. Very little dependencies: basically, mdz_vector functions are only dependent on standard C-library memory-management/access functions. Multithreading part is dependent on POSIX pthreads API (under UNIX/Linux) and old process
control/synchronization API (from Windows 2000). It means you can use library in your code without any further dependencies except standard platform libraries/APIs.
3. Very fast: comparison tables are coming soon...
4. Flexibilty: nearly all functions contain not only "left position" but also "right position" parameters to limit processed area from right. Vector contains more functions than according STL, boost or glib analogs have.
5. Extended error-checking: all functions preserve internal error-code pointing the problem. It is possible to use strict error-checking (when all preserved error-codes should be MDZ_ERROR_NONE) or "relaxed"-checking - when only
returned mdz_false will indicate error.
6. Extended control: vector does only explicit operations. It means for example, when "insert" function is called - it will return error if there is not enough capacity in vector. No implicit reservations will be made.
7. Attached usage: vector should not necessarily use dynamically-allocated memory - which may be not available on your embedded system (or if malloc()/free() are forbidden to use in you safety-critical software).
Just attach vector/data to your statically-allocated memory and use all vector functionality.
8. Asynchronous execution: almost all functions can be executed asynchronously.
mdz_vector API Reference
Asynchronous executionMany functions of mdz_vector accept parameters for asynchronous execution.
The only relevant parameter is: - struct mdz_asyncData* pAsyncData - pointer to shared async data for asynchronous call, or NULL if call should be synchronous
Fields of struct mdz_asyncData* are following:
Type | Parameter | Description |
void* | m_pString | Pointer to string instance |
mdz_bool | m_bFinished | mdz_true if the call is completely finished. Otherwise mdz_false (if interrupted/cancelled) |
size_t | m_nResult | Result of call. Invalid if call is not completely finished (m_bFinished is mdz_false ) |
void* | m_pData | Additional data returned by call (if any). Invalid if call is not completely finished (m_bFinished is mdz_false ) |
mdz_bool | m_bCancel | Should be set by client in mdz_true during call execution, to cancel the call. Otherwise mdz_false |
pthread_t / HANDLE | m_hThread | Handle to thread on which the call is executed. May be used by client for wait operations |
mdz_vector is dynamically-sized contiguous container.
Capacity - how many items memory is reserved for.
Size - how many items are actually residing in a vector.
"reserve/AndReserve" functions allocate/reallocate memory dynamically using malloc() /realloc() .
"attach" functionality allows attaching contiguous block of memory to vector, for using vector functions on it.
Library init functions:
mdz_vector_init
mdz_vector_init_attached
mdz_vector_uninit
mdz_vector_create
mdz_vector_create_attached
mdz_vector_destroy
mdz_vector_clear
mdz_vector_attachData
Reserve capacity functions:
mdz_vector_reserve
mdz_vector_reserveAndInit
mdz_vector_capacity
mdz_vector_size
mdz_vector_resize
mdz_vector_offsetFromStart
mdz_vector_isAttachedData
Insert/remove functions:
mdz_vector_insert
mdz_vector_append
mdz_vector_removeFrom
mdz_vector_remove
mdz_vector_trimLeft
mdz_vector_trimRight
mdz_vector_trim
Find functions:
mdz_vector_findSingle
mdz_vector_find
mdz_vector_firstOf
mdz_vector_firstNotOf
mdz_vector_rfindSingle
mdz_vector_rfind
mdz_vector_lastOf
mdz_vector_lastNotOf
Miscellaneous functions:
mdz_vector_compare
mdz_vector_replace
mdz_vector_count
mdz_vector_copySubVector
mdz_vector_copySubVectorFrom
Initializes vector library. This function should be called before any other function of the library.
mdz_bool mdz_vector_init(const unsigned long* pFirstNameHash, const unsigned long* pLastNameHash, const unsigned long* pEmailHash, const unsigned long* pLicenseHash);
Parameter | Description |
pFirstNameHash | user first name hash code |
pLastNameHash | user last name hash code |
pEmailHash | user e-mail hash code |
pLicenseHash | license hash code |
Return | Description |
mdz_true | if the initialization has succeed, otherwise false |
mdz_vector Reference
Initializes vector library. This function should be caled before any other function of the library. Memory for license data starts at position pStart . Size of internal initialization structure is returned in pSize.
mdz_bool mdz_vector_init_attached(const unsigned long* pFirstNameHash, const unsigned long* pLastNameHash, const unsigned long* pEmailHash, const unsigned long* pLicenseHash, const char* pStart, size_t nAreaSize, size_t* pOutSize);
Parameter | Description |
pFirstNameHash | user first name hash code |
pLastNameHash | user last name hash code |
pEmailHash | user e-mail hash code |
pLicenseHash | license hash code |
pStart | memory start position of license data |
nAreaSize | size of available memory from pStart in bytes. Should be large enough for license data (> 500 bytes) |
pOutSize | actual size of placed license data in bytes |
Return | Description |
mdz_true | if the initialization has succeed, otherwise false |
mdz_vector Reference
Un-initializes vector library and frees corresponding memory allocations.
void mdz_vector_uninit(void);
mdz_vector Reference
Create empty vector with Capacity and Size 0. Memory for vector structure is allocated using malloc() .
struct mdz_Vector* mdz_vector_create(size_t nTypeSize);
Parameter | Description |
nTypeSize | sizeof of type used in vector. Allowed nTypeSize are 1, 2, 4 or 8 |
Return | Description |
NULL | if library is not initialized with mdz_containers_init() call |
NULL | if not allowed nTypeSize is used |
NULL | if memory allocation failed |
Result | pointer to vector for use in other mdz_vector functions |
mdz_vector Reference
Create empty vector with Capacity and Size 0. Memory for vector structure starts at position pStart . Size in bytes of internal vector structure (it is usually bigger than mdz_Vector !) is returned in pSize .
struct mdz_Vector* mdz_vector_create_attached(size_t nTypeSize, const void* pStart, size_t* pSize);
Parameter | Description |
nTypeSize | sizeof of type used in vector. Allowed nTypeSize are 1, 2, 4 or 8 |
pStart | memory start position of vector structure |
pSize | initially should contain size of available memory from pStart . After vector creation - contains actual size of internal vector structure |
Return | Description |
NULL | if library is not initialized with mdz_containers_init() call |
NULL | if not allowed nTypeSize is used |
NULL | if pStart == NULL or pSize == NULL |
NULL | if size in pSize is smaller than size of internal vector structure |
Result | pointer to vector for use in other mdz_vector functions. Normally it equals to pStart |
mdz_vector Reference
Destroy vector including underlying data using free() . If vector is attached using mdz_vector_create_attached() , vector controlling data will not be destroyed. If vector data is attached using mdz_vector_attachData() , m_pData will not be destroyed.
void mdz_vector_destroy(const struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
mdz_vector Reference
Clear m_pData of vector with setting Size in 0.
void mdz_vector_clear(struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() |
mdz_vector Reference
Attach pre-allocated data to vector, assigning pData to m_pData . If attached, m_pData will not be destroyed in mdz_vector_destroy()
mdz_bool mdz_vector_attachData(struct mdz_Vector* pVector, void* pData, size_t nOffsetFromStart, size_t nCapacity, enum mdz_attach_type enAttachType);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
pData | pointer to pre-allocated data to attach |
nOffsetFromStart | position in pre-allocated data to attach from. Can be > 0 |
nCapacity | full capacity pre-allocated data in items |
enAttachType | type of attachment. Only MDZ_ATTACH_ZEROSIZE and MDZ_ATTACH_SIZE_NO_TERMINATOR are allowed |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if pData == NULL (MDZ_ERROR_DATA), or nOffsetFromStart >= nCapacity (MDZ_ERROR_OFFSET), or invalid enAttachType (MDZ_ERROR_ATTACHTYPE) |
mdz_true | operation succeeded |
mdz_vector Reference
Reserve nNewCapacity items for vector. Vector Size does not change. Reservation is not made if m_pData is attached using mdz_vector_attachData()
mdz_bool mdz_vector_reserve(struct mdz_Vector* pVector, size_t nNewCapacity);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nNewCapacity | new capacity in items to reserve |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if memory allocation failed (MDZ_ERROR_ALLOCATION) |
mdz_false | if m_pData is attached using mdz_vector_attachData() (MDZ_ERROR_ATTACHED) |
mdz_true | reservation succeeded, or nNewCapacity <= Capacity (MDZ_ERROR_CAPACITY) |
mdz_vector Reference
Reserve nNewCapacity items for vector and initializes all items in pItem . May be called only on empty vectors (with Size == 0). After call, vector Size equals to Capacity . Reservation is not made if m_pData is attached using mdz_vector_attachData() and nNewCapacity > Capacity
mdz_bool mdz_vector_reserveAndInit(struct mdz_Vector* pVector, size_t nNewCapacity, const void* pItem);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nNewCapacity | capacity to reserve in items |
pItem | item for vector initialization. If NULL , 0 will be used for initialization |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if memory allocation failed (MDZ_ERROR_ALLOCATION) |
mdz_false | if Size > 0 (MDZ_ERROR_NONEMPTY) |
mdz_false | if m_pData is attached using mdz_vector_attachData() (MDZ_ERROR_ATTACHED) |
mdz_true | if nNewCapacity <= Capacity (MDZ_ERROR_CAPACITY), initialization succeeded |
mdz_true | reservation and initialization succeeded |
mdz_vector Reference
Return vector Capacity in items.
size_t mdz_vector_capacity(const struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
Return | Description |
0 | if pVector == NULL |
Capacity | otherwise |
mdz_vector Reference
Return vector Size in items.
size_t mdz_vector_size(const struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
Return | Description |
0 | if pVector == NULL |
Size | otherwise |
mdz_vector Reference
Set vector Size . Size must be <= Capacity .
mdz_bool mdz_vector_resize(struct mdz_Vector* pVector, size_t nNewSize);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nNewSize | new Size to set vector in |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if nNewSize > Capacity (MDZ_ERROR_CAPACITY). Vector Size is not changed |
mdz_true | if succeeded |
mdz_vector Reference
Return vector OffsetFromStart in items.
size_t mdz_vector_offsetFromStart(const struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
Return | Description |
0 | if pVector == NULL |
OffsetFromStart | otherwise |
mdz_vector Reference
Return if vector data is attached.
mdz_bool mdz_vector_isAttachedData(const struct mdz_Vector* pVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if vector data is not attached |
mdz_true | if vector data is attached |
mdz_vector Reference
Insert nCount items in vector. Capacity should contain enough free space for nCount items. Vector m_pData and pItems cannot overlap. Size grows on nCount .
mdz_bool mdz_vector_insert(struct mdz_Vector* pVector, size_t nLeftPos, const void* pItems, size_t nCount, mdz_bool bReserve);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based position to insert. If nLeftPos == Size or -1, items are appended. nLeftPos > Size is not allowed |
pItems | items to insert. If NULL , 0 will be used for insertion nCount times |
nCount | number of items to insert |
bReserve | if mdz_true reserve capacity when there is not enough space for insertion, otherwise mdz_false |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if bReserve == mdz_true and memory allocation failed (MDZ_ERROR_ALLOCATION) |
mdz_false | if bReserve == mdz_true and there is not enough capacity for inserted data but m_pData is attached using mdz_vector_attachData() (MDZ_ERROR_ATTACHED) |
mdz_false | if bReserve == mdz_false and there is not enough free Capacity in the vector (MDZ_ERROR_CAPACITY) |
mdz_true | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > Size (MDZ_ERROR_BIGLEFT), or nCount is too big (MDZ_ERROR_BIGCOUNT). No insertion is made |
mdz_true | insertion succeeded |
mdz_vector Reference
Appends nCount items in vector. Capacity should contain enough free space for nCount items. Vector m_pData and pItems cannot overlap. Size grows on nCount .
mdz_bool mdz_vector_append(struct mdz_Vector* pVector, const void* pItems, size_t nCount, mdz_bool bReserve);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
pItems | items to insert. If NULL , 0 will be used for insertion nCount times |
nCount | number of items to insert |
bReserve | if mdz_true reserve capacity when there is not enough space for insertion, otherwise mdz_false |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if bReserve == mdz_true and memory allocation failed (MDZ_ERROR_ALLOCATION) |
mdz_false | if bReserve == mdz_true and there is not enough capacity for inserted data but m_pData is attached using mdz_vector_attachData() (MDZ_ERROR_ATTACHED) |
mdz_false | if bReserve == mdz_false and there is not enough free Capacity in the vector (MDZ_ERROR_CAPACITY) |
mdz_true | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nCount is too big (MDZ_ERROR_BIGCOUNT). No insertion is made |
mdz_true | insertion succeeded |
mdz_vector Reference
Find first occurrence of pItem in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_findSingle(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItem);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of vector |
pItem | pointer to item to find. If NULL , value type of NULL (normally 0) nCount times, will be used for search |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find first occurrence of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_find(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount, enum mdz_ansi_find_method enFindMethod);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of vector |
pItems | pointer to items to find. If NULL , value type of NULL (normally 0) nCount times, will be used for search |
nCount | number of items to find |
enFindMethod | find method to use. See details in mdz_find_method description |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nCount is too big (MDZ_ERROR_BIGCOUNT), or invalid enFindMethod (MDZ_ERROR_FINDMETHOD). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find first occurrence of any item of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_firstOf(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of vector |
pItems | pointer to items to find. If NULL , 0 will be used for search |
nCount | number of items to find. 1 if pItems == NULL |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find first non-occurrence of any item of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_firstNotOf(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of vector |
pItems | pointer to items to check. If NULL , 0 will be used for search |
nCount | number of items to check. 1 if pItems == NULL |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No search is made |
Size | if non-occurrence is not found |
Result | 0-based position of first non-occurrence |
mdz_vector Reference
Find last occurrence of pItem in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_rfindSingle(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItem);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of vector |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of vector |
pItem | pointer to items to find. If NULL , value type of NULL (normally 0) nCount times, will be used for search |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nLeftPos + nCount > Size (MDZ_ERROR_BIGCOUNT). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find last occurrence of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_rfind(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount, enum mdz_ansi_find_method enFindMethod);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of vector |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of vector |
pItems | pointer to items to find. If NULL , value type of NULL (normally 0) nCount times, will be used for search |
nCount | number of items to find |
enFindMethod | find method to use. See details in mdz_find_method description |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nLeftPos + nCount > Size (MDZ_ERROR_BIGCOUNT), or invalid enFindMethod (MDZ_ERROR_FINDMETHOD). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find last occurrence of any item of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_lastOf(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based end position to search up to. Use 0 to search till the beginning of vector |
nRightPos | 0-based start position to search from right. Use Size-1 to search from the end of vector |
pItems | pointer to items to find. If NULL , value type of NULL (normally 0) will be used for search |
nCount | number of items to find |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No search is made |
Size | if item(s) not found |
Result | 0-based position of first match |
mdz_vector Reference
Find last non-occurrence of any item of pItems in vector. Returns 0-based position of match (if found), or vector Size if not found, or SIZE_MAX if error.
size_t mdz_vector_lastNotOf(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based end position to search up to. Use 0 to search till the beginning of vector |
nRightPos | 0-based start position to search from right. Use Size-1 to search from the end of vector |
pItems | pointer to items to find. If NULL , value type of NULL (normally 0) will be used for search |
nCount | number of items to find |
Return | Description |
SIZE_MAX | if pVector == NULL |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No search is made |
Size | if non-occurrence is not found |
Result | 0-based position - position of first match |
mdz_vector Reference
Remove nCount item(s) starting from 0-based nLeftPos position. After the operation, Capacity doesn't change, Size decreases on nCount .
mdz_bool mdz_vector_removeFrom(struct mdz_Vector* pVector, size_t nLeftPos, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to remove item(s) from. Use 0 to remove from the beginning of vector |
nCount | number of item(s) to remove. Assure that nLeftPos + nCount - 1 < Size - otherwise no removes will be made |
Return | Description |
mdz_false | if pVector == NULL |
mdz_true | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nCount is too big (MDZ_ERROR_BIGCOUNT), or nLeftPos + nCount > Size (MDZ_ERROR_BIGLEFT). No removes are made |
mdz_true | operation succeeded |
mdz_vector Reference
Remove all occurrences of nCount item(s) matching to pItems , residing between nLeftPos and nRightPos . Vector m_pData and pItems cannot overlap. After remove(s) Capacity doesn't change, Size decreases on nCount of removed items.
mdz_bool mdz_vector_remove(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to remove item(s) from. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to remove item(s) up to. Use Size-1 to search till the end of vector |
pItems | pointer to items to remove. If NULL , value type of NULL (normally 0) nCount times, will be used for search |
nCount | number of item(s) to remove |
Return | Description |
mdz_false | if pVector == NULL |
mdz_true | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nCount is too big (MDZ_ERROR_BIGCOUNT). No removes are made |
mdz_true | operation succeeded |
mdz_vector Reference
Remove items which are contained in pItems from left, until first non-contained in pItems item is reached. Vector m_pData and pItems cannot overlap.
mdz_bool mdz_vector_trimLeft(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to trim item(s) from left. Use 0 to trim from the beginning of vector |
nRightPos | 0-based end position to trim item(s) up to. Use Size-1 to trim till the end of vector |
pItems | pointer to items to remove. If NULL , value type of NULL (normally 0) will be used |
nCount | number of items to remove. If pItems is NULL , nCount is set to 1 |
Return | Description |
mdz_false | if pVector == NULL |
mdz_true | if vector is empty (MDZ_ERROR_EMPTY), or nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No trims are made |
mdz_true | operation succeeded |
mdz_vector Reference
Remove items which are contained in pItems from right, until first non-contained in pItems item is reached. Vector m_pData and pItems cannot overlap.
mdz_bool mdz_vector_trimRight(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based end position to trim item(s) up to. Use 0 to trim till the beginning of vector |
nRightPos | 0-based start position to trim item(s) from right. Use Size-1 to trim from the end of vector |
pItems | pointer to items to remove. If NULL , value type of NULL (normally 0) will be used |
nCount | number of items to remove. If pItems is NULL , nCount is set to 1 |
Return | Description |
mdz_false | if pVector == NULL |
mdz_true | if vector is empty (MDZ_ERROR_EMPTY), or nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No removes are made |
mdz_true | operation succeeded |
mdz_vector Reference
Remove items which are contained in pItems from left and from right, until first non-contained in pItems item is reached. Vector m_pData and pItems cannot overlap.
mdz_bool mdz_vector_trim(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to trim item(s) from left. Use 0 to trim from the beginning of vector |
nRightPos | 0-based start position to trim item(s) from right. Use Size-1 to trim from the end of vector |
pItems | pointer to items to remove. If NULL , value type of NULL (normally 0) will be used |
nCount | number of items to remove. If pItems is NULL , nCount is set to 1 |
Return | Description |
mdz_false | if pVector == NULL |
mdz_true | if vector is empty (MDZ_ERROR_EMPTY), or nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No removes are made |
mdz_true | operation succeeded |
mdz_vector Reference
Compare content of vector with pItems .
enum mdz_compare_result mdz_vector_compare(struct mdz_Vector* pVector, size_t nLeftPos, const void* pItems, size_t nCount);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to compare from. Use 0 to compare from the beginning of vector |
pItems | pointer to items to compare. If NULL , value type of NULL (normally 0) nCount times, will be used for comparison |
nCount | number of items to compare |
Return | Description |
MDZ_COMPARE_ERROR | if pVector == NULL |
MDZ_COMPARE_NONEQUAL | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nCount is too big (MDZ_ERROR_BIGCOUNT), or nLeftPos + nCount > Size (MDZ_ERROR_BIGLEFT). No comparison is made |
MDZ_COMPARE_EQUAL or MDZ_COMPARE_NONEQUAL | Result of comparison |
mdz_vector Reference
Replace every occurrence of pItemsBefore with pItemsAfter . There should be enough Capacity for replacing data. Vector m_pData and pItemsBefore /pItemsAfter cannot overlap.
mdz_bool mdz_vector_replace(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItemsBefore, size_t nCountBefore, const void* pItemsAfter, size_t nCountAfter, mdz_bool bReserve);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to search for replace from. Use 0 to search from the beginning of vector |
nRightPos | 0-based end position to search for replace up to. Use Size-1 to search till the end of vector |
pItemsBefore | pointer to items to replace. If NULL , value type of NULL (normally 0) nCountBefore times, will be searched |
nCountBefore | number of items to replace |
pItemsAfter | pointer to items to replace with. If NULL , value type of NULL (normally 0) nCountAfter times, will be used to replace |
nCountAfter | number of items to replace with |
bReserve | if mdz_true reserve capacity when there is not enough space for replacement, otherwise mdz_false |
Return | Description |
mdz_false | if pVector == NULL |
mdz_false | if bReserve == mdz_true and there is not enough capacity for inserted data but m_pData is attached using mdz_vector_attachData() (MDZ_ERROR_ATTACHED) |
mdz_false | if bReserve == mdz_false and there is not enough free Capacity in the vector (MDZ_ERROR_CAPACITY) |
mdz_true | if nCountBefore == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nCountBefore is too big (MDZ_ERROR_BIGCOUNT). No replacements is made |
mdz_true | operation succeeded |
mdz_vector Reference
Counts number of pItems subvector occurrences in vector.
size_t mdz_vector_count(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pItems, size_t nCount, mdz_bool bAllowOverlapped);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to count from. Use 0 to count from the beginning of vector |
nRightPos | 0-based end position to count up to. Use Size-1 to count till the end of vector |
pItems | items/subvector to count. If NULL , value type of NULL (normally 0) nCount times, will be counted |
nCount | length of subvector to count |
bAllowOverlapped | mdz_true if overlapped subvectors should be counted, otherwise mdz_false |
Return | Description |
SIZE_MAX | if pVector == NULL |
0 | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT), or nCount is too big (MDZ_ERROR_BIGCOUNT). No counting is made |
Result | 0-based count of subvector occurrences. 0 if not found |
mdz_vector Reference
Fills pSubVector with items, starting from nLeftPos and ending with one of pSeparators or nRightPos .
size_t mdz_vector_copySubVector(struct mdz_Vector* pVector, size_t nLeftPos, size_t nRightPos, const void* pSeparators, size_t nSeparatorsCount, struct mdz_Vector* pSubVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to get items from. Use 0 to start from the beginning of vector |
nRightPos | 0-based end position to get items up to. Use Size-1 to proceed till the end of vector |
pSeparators | separators to get items up to. If NULL , value type of NULL (normally 0) will be used |
nSeparatorsCount | number of separators |
pSubVector | pointer to vector where items should be copied. Data in pSubVector will be re-reserved to appropriate size if necessary |
Return | Description |
SIZE_MAX | if pVector == NULL , or pSubVector == NULL (MDZ_ERROR_SUBCONTAINER), or reallocation of m_pData in pSubVector was necessary but failed (MDZ_ERROR_ALLOCATION) |
Size | if nSeparatorsCount == 0 (MDZ_ERROR_ZEROCOUNT), or nLeftPos > nRightPos (MDZ_ERROR_BIGLEFT), or nRightPos >= Size (MDZ_ERROR_BIGRIGHT). No copying is made |
Result | 0-based position after separator if found, or Size if not found |
mdz_vector Reference
Fills pSubVector with items, starting from nLeftPos and containing nCount items.
size_t mdz_vector_copySubVectorFrom(struct mdz_Vector* pVector, size_t nLeftPos, size_t nCount, struct mdz_Vector* pSubVector);
Parameter | Description |
pVector | pointer to vector returned by mdz_vector_create() or mdz_vector_create_attached() |
nLeftPos | 0-based start position to get items from. Use 0 to start from the beginning of vector |
nCount | number of items to copy |
pSubVector | pointer to vector where items should be copied. Data in pSubVector will be re-reserved to appropriate size if necessary |
Return | Description |
SIZE_MAX | if pVector == NULL , or pSubVector == NULL (MDZ_ERROR_SUBCONTAINER), or reallocation of m_pData in pSubVector was necessary but failed (MDZ_ERROR_ALLOCATION) |
Size | if nCount == 0 (MDZ_ERROR_ZEROCOUNT), or nCount is too big (MDZ_ERROR_BIGCOUNT), or nLeftPos + nCount > Size (MDZ_ERROR_BIGLEFT). No copying is made |
Result | 0-based position after copied data |
mdz_vector Reference
|