uLib
User mode C/C++ extended API library for Win32 programmers.
|
#include <uLib/StrFunc.h>
WordList is a sorted list of unique strings (duplicates are excluded).
It adds sorting, duplicate culling, and indexed access to StringCache.
Memory is chunk-wise allocated on demand by AddString(), and freed by the d'tor.
WordList is intended for memory-efficient string lists, f.ex. keyword tables,
and therefore doesn't support Unicode strings.
It is designed to be fast, by utilizing iterative binary search and pre-allocation.
Note: You may use the underlying Storage for multi-string operations,
however, the Storage cache is not sorted, only the Strings array is.
Example: Using bsearch() to search a WordList..
Public Data | |
char ** | Strings |
UINT | Count |
![]() | |
char * | Storage |
Public Functions | |
WordList (UINT InitListDim=128, UINT InitStgSize=4096, UINT ListGrowBy=128, UINT StgGrowBy=4096) | |
~WordList () | |
bool | AddString (char *Str, bool caseSens=true) |
char * | Search (char *Key, int(__stdcall *Compare)(char *Key, char *Str, void *Ctx), void *Context) |
void | Reset () |
void | Free () |
![]() | |
StringCache (UINT InitSize=4096, UINT ChunkSize=4096) | |
~StringCache () | |
char * | DupStr (char *Str) |
void | Reset () |
void | Free () |
int | StorageSize () |
int | StorageUsed () |
Protected Member Functions | |
bool | Grow () |
![]() | |
bool | GrowStorage () |
Protected Attributes | |
UINT | Dim |
UINT | ListChunk |
![]() | |
UINT | StgSize |
UINT | StgUsed |
UINT | StgChunk |
WordList::WordList | ( | UINT | InitListDim = 128 , |
UINT | InitStgSize = 4096 , |
||
UINT | ListGrowBy = 128 , |
||
UINT | StgGrowBy = 4096 |
||
) |
Use the constuctor parameters to optimize your memory use.
InitListDim | Nr of string ptrs in initial allocation. |
ListGrowBy | Nr of string ptrs per additional allocation. |
InitStgSize | Block size of initial StringCache allocation. |
StgGrowBy | StringCache chunk size to add per reallocation. |
Definition at line 1758 of file StrFunc.cpp.
WordList::~WordList | ( | ) |
The d'tor deallocates Strings and Storage.
Definition at line 1768 of file StrFunc.cpp.
bool WordList::AddString | ( | char * | Str, |
bool | caseSens = true |
||
) |
AddString() adds a string to the list if it doesn't exist already.
It returns true if Str was added, or false if it was already present.
Use caseSens to specify if the comparator should be case sensitive or not.
Definition at line 1803 of file StrFunc.cpp.
char * WordList::Search | ( | char * | Key, |
int(__stdcall *Compare)(char *Key, char *Str, void *Ctx) | , | ||
void * | Context | ||
) |
Search does a binary search of the WordList content.
Return the string matching Key, or NULL on failure.
Note: This function avoids the problems in bsearch() implementation.
Definition at line 1875 of file StrFunc.cpp.
void WordList::Reset | ( | ) |
Un-use all memory.. No deallocation.
Definition at line 1773 of file StrFunc.cpp.
void WordList::Free | ( | ) |
Deallocate all memory.
Definition at line 1779 of file StrFunc.cpp.
|
protected |
Definition at line 1786 of file StrFunc.cpp.
char** WordList::Strings |
UINT WordList::Count |