New update! 3.1 is liiiive!
Error handling: Array now has sufficiently advanced error handling to remove most, if not all, disable_checks. Extention: With the metaprogramming techniques, new types can be added easily. Speed: With the new changes I've made to Judy, the Array module has far exceeded the speed of any traditional datatype
This commit is contained in:
73
dlls/arrayx/CArray.h
Normal file
73
dlls/arrayx/CArray.h
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef _ARRAYCLASS_H
|
||||
#define _ARRAYCLASS_H
|
||||
|
||||
#include "JudyIncludes.h"
|
||||
#include "CBaseList.h"
|
||||
#include "JudyExtra.h"
|
||||
//#include <JudyL.h>
|
||||
|
||||
class Array: public CBaseList
|
||||
{
|
||||
private:
|
||||
Pvoid_t Table;
|
||||
|
||||
void ThrowIndexError( cell index, bool disable_check = false );
|
||||
void ThrowSearchError(char* msg);
|
||||
|
||||
public:
|
||||
Array() { Table = NULL; }
|
||||
~Array() { Clear(); }
|
||||
|
||||
Word_t Clear() { JudyClearList(this); return JudyLFreeArray(&Table, PJE0); }
|
||||
Word_t MemoryUsed() { return JudyLMemUsed(Table); }
|
||||
|
||||
int Delete(cell Key) { delete Get(Key,true); return JudyLDel(&Table, Key, PJE0 ); }
|
||||
|
||||
void Set(cell Index, Pvoid_t value, bool disable_check)
|
||||
{
|
||||
PPvoid_t PValue = JudyLIns(&Table, Index,PJE0);
|
||||
*PValue = value;
|
||||
}
|
||||
|
||||
Pvoid_t Get(cell Index, bool disable_check = false)
|
||||
{
|
||||
PPvoid_t PValue = JudyLGet(Table, Index, PJE0);
|
||||
if(PValue == NULL) { ThrowIndexError(Index, disable_check); return NULL; }
|
||||
|
||||
return *PValue;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void Set(cell Index, Type value)
|
||||
{
|
||||
PPvoid_t PValue = JudyLIns(&Table, Index,PJE0);
|
||||
*PValue = reinterpret_cast<void*>(value);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
Type Get(cell Index, Type example, bool disable_check = false)
|
||||
{
|
||||
PPvoid_t PValue = JudyLGet(Table, Index, PJE0);
|
||||
if(PValue == NULL) { ThrowIndexError(Index, disable_check); return (Type)NULL; }
|
||||
|
||||
return (Type)(*PValue);
|
||||
}
|
||||
|
||||
cell First(cell Start = 0);
|
||||
cell Next(cell Start = 0);
|
||||
cell Prev(cell Start = -1);
|
||||
cell Last(cell Start = -1);
|
||||
|
||||
cell FirstEmpty(cell Start = 0);
|
||||
cell NextEmpty(cell Start = 0);
|
||||
cell PrevEmpty(cell Start = -1);
|
||||
cell LastEmpty(cell Start = -1);
|
||||
|
||||
cell ByCount(cell n, cell Start = 0);
|
||||
cell Count(cell Start = 0, cell Stop = -1) { return JudyLCount(Table, Start, Stop, PJE0); }
|
||||
|
||||
bool IsFilled(cell Index) { return ( (Get(Index, true ) != NULL) ? true : false); }
|
||||
bool IsEmpty(cell Index) { return ( (Get(Index, true ) == NULL) ? true : false); }
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user