29#define DISABLE_DEBUGLOG
32#include "idlist64_p.h"
34#include <gwenhywfar/memory.h>
35#include <gwenhywfar/debug.h>
120 for (i=0; i<tableCount; i++) {
121 const GWEN_IDTABLE64 *oldTable;
125 GWEN_IDTABLE64 *table;
249 if (entriesPerTable) {
253 tablePos=idx/entriesPerTable;
262 entryPos=idx%entriesPerTable;
263 return entries[entryPos];
279int GWEN_IdList64_SetIdAt(
GWEN_IDLIST64 *idl, uint64_t idx, uint64_t entry)
291 if (entriesPerTable) {
295 tablePos=idx/entriesPerTable;
302 GWEN_IDTABLE64 *pTableCopy;
314 entryPos=idx%entriesPerTable;
315 entries[entryPos]=entry;
337 GWEN_IDTABLE64 *pTableCurrent=
NULL;
338 int64_t idxTableCurrent=0;
356 if (idxTableCurrent>=0)
362 if (pTableCurrent==
NULL) {
375 if (idxTableCurrent<0) {
378 return idxTableCurrent;
386 int64_t index=idxTableCurrent*entriesPerTable;
391 GWEN_IDTABLE64 *pTableCopy;
397 pTableCurrent=pTableCopy;
415 if (ptr[entryPos]!=0) {
423 for (entryPos=0; entryPos<entriesPerTable; entryPos++) {
424 if (ptr[entryPos]==0)
431 (
unsigned long) entryPos,
432 (
unsigned long) idxTableCurrent,
433 (
unsigned long) index,
434 (
unsigned long)(index+entryPos));
436 if (entryPos<entriesPerTable) {
465 for (idx=0; idx<numTables; idx++) {
472 for (i=0; i<entriesPerTable; i++) {
473 if (idt->ptrEntries[i]==wantedId) {
490 for (idx=0; idx<numTables; idx++) {
497 for (i=0; i<entriesPerTable; i++) {
498 if (idt->ptrEntries[i]==wantedId) {
499 idt->ptrEntries[i]=0;
517 ft=(GWEN_IDTABLE64 *) p;
527 ft=(GWEN_IDTABLE64 *) p;
541 for (idx=0; idx<numTables; idx++) {
549 for (i=0; i<entriesPerTable; i++) {
550 if (idt->ptrEntries[i]!=0) {
551 id=idt->ptrEntries[i];
557 idIndex+=entriesPerTable;
575 tableNum=*pos / entriesPerTable;
576 tableIdx=*pos % entriesPerTable;
578 if (tableNum>numTables) {
584 idIndex=(tableNum*entriesPerTable);
586 for (idx=tableNum; idx<numTables; idx++) {
595 for (i=tableIdx; i<entriesPerTable; i++) {
596 if (idt->ptrEntries[i]!=0) {
597 id=idt->ptrEntries[i];
604 for (i=0; i<entriesPerTable; i++) {
605 if (idt->ptrEntries[i]!=0) {
606 id=idt->ptrEntries[i];
613 idIndex+=entriesPerTable;
639 ptr=(uint64_t *)malloc(
sizeof(uint64_t)*entryCount);
643 for (i=0; i<entryCount; i++) {
664 for (i=0; i<entryCount; i++) {
690 uint64_t a=*((
const uint64_t *)pa);
691 uint64_t b=*((
const uint64_t *)pb);
705 uint64_t a=*((
const uint64_t *)pa);
706 uint64_t b=*((
const uint64_t *)pb);
789 assert(ft && ft->refCount);
790 if (ft && ft->refCount) {
800 assert(ft->refCount);
801 if (ft->refCount==1) {
803 free(ft->ptrEntries);
827 assert(ftOrig->refCount);
829 ft->maxEntries=ftOrig->maxEntries;
830 ft->freeEntries=ftOrig->freeEntries;
831 ft->highestEntry=ftOrig->highestEntry;
832 ft->runtimeFlags=ftOrig->runtimeFlags;
835 if (ftOrig->maxEntries && ftOrig->ptrEntries) {
836 uint64_t offsetArraySize;
838 offsetArraySize=ftOrig->maxEntries*
sizeof(uint64_t);
839 ft->ptrEntries=(uint64_t *) malloc(offsetArraySize);
840 assert(ft->ptrEntries);
841 memmove(ft->ptrEntries, ftOrig->ptrEntries, offsetArraySize);
852 uint64_t offsetArraySize;
856 ft->maxEntries=maxEntries;
857 ft->freeEntries=maxEntries;
859 offsetArraySize=ft->maxEntries*
sizeof(uint64_t);
861 ptr=(uint64_t *) malloc(offsetArraySize);
863 memset(ptr, 0, offsetArraySize);
874 assert(ft->refCount);
875 return ft->maxEntries;
883 assert(ft->refCount);
884 return ft->freeEntries;
892 assert(ft->refCount);
893 if (ft->freeEntries>0)
902 assert(ft->refCount);
903 return ft->highestEntry;
911 assert(ft->refCount);
912 if (i>ft->highestEntry)
921 assert(ft->refCount);
922 return ft->ptrEntries;
930 assert(ft->refCount);
931 if (ft->ptrEntries && ft->ptrEntries!=ptr)
932 free(ft->ptrEntries);
941 return ft->runtimeFlags;
#define DBG_VERBOUS(dbg_logger, format, args...)
#define DBG_INFO(dbg_logger, format, args...)
#define DBG_ERROR(dbg_logger, format, args...)
#define GWEN_ERROR_INTERNAL
#define GWEN_ERROR_INVALID
#define GWEN_ERROR_BUFFER_OVERFLOW
#define GWEN_ERROR_NO_DATA
GWEN_IDLIST64 * GWEN_IdList64_newWithSteps(uint64_t steps)
int GWEN_IdList64_SetTableAt(GWEN_IDLIST64 *idl, uint64_t idx, GWEN_IDTABLE64 *t)
int64_t GWEN_IdList64_GetLastTablePos(const GWEN_IDLIST64 *idl)
int GWEN_IdList64_GetTableMaxEntries(const GWEN_IDLIST64 *idl)
void GWEN_IdList64_Iterator_free(GWEN_IDLIST64_ITERATOR *it)
static GWEN_IDTABLE64 * GWEN_IdList64_GetTableAt(const GWEN_IDLIST64 *tl, uint64_t idx)
uint64_t GWEN_IdList64_Iterator_GetNextId(GWEN_IDLIST64_ITERATOR *it)
void GWEN_IdList64_free(GWEN_IDLIST64 *idl)
GWEN_IDLIST64 * GWEN_IdList64_new()
static void GWEN_IdTable64_SetPtrEntries(GWEN_IDTABLE64 *ft, uint64_t *ptr)
static uint64_t GWEN_IdList64__GetFirstId(const GWEN_IDLIST64 *idl, uint64_t *pos)
GWEN_IDLIST64 * GWEN_IdList64_dup(const GWEN_IDLIST64 *oldList)
static void GWEN_IdTable64_DecFreeEntries(GWEN_IDTABLE64 *ft)
int GWEN_IdList64_Sort(GWEN_IDLIST64 *idl)
static void GWEN_IdTable64_Attach(GWEN_IDTABLE64 *ft)
static GWEN_IDTABLE64 * GWEN_IdTable64_dup(const GWEN_IDTABLE64 *ftOrig)
static void GWEN_IdTable64_CheckAndSetHighestEntry(GWEN_IDTABLE64 *ft, uint64_t i)
int GWEN_IdTable64_GetRefCounter(const GWEN_IDTABLE64 *ft)
static int GWEN_IdList64__Sort(GWEN_IDLIST64 *idl, int ascending)
static uint64_t GWEN_IdTable64_GetFreeEntries(const GWEN_IDTABLE64 *ft)
int GWEN_IdList64_DelId(GWEN_IDLIST64 *idl, uint64_t wantedId)
static void GWEN_IdTable64_AddRuntimeFlags(GWEN_IDTABLE64 *ft, uint32_t i)
static uint64_t GWEN_IdList64__GetNextId(const GWEN_IDLIST64 *idl, uint64_t *pos)
static uint64_t * GWEN_IdTable64_GetPtrEntries(const GWEN_IDTABLE64 *ft)
uint64_t GWEN_IdList64_Iterator_GetFirstId(GWEN_IDLIST64_ITERATOR *it)
void GWEN_IdList64_IncIdCounter(GWEN_SIMPLEPTRLIST *pl)
static GWENHYWFAR_CB void _attachToTable(GWEN_SIMPLEPTRLIST *pl, void *p)
static void GWEN_IdTable64_free(GWEN_IDTABLE64 *ft)
int GWEN_IdList64_ReverseSort(GWEN_IDLIST64 *idl)
void GWEN_IdList64_Attach(GWEN_IDLIST64 *idl)
int64_t GWEN_IdList64_AddId(GWEN_IDLIST64 *idl, uint64_t entry)
static uint64_t GWEN_IdTable64_GetMaxEntries(const GWEN_IDTABLE64 *ft)
int64_t GWEN_IdList64_GetIdAt(const GWEN_IDLIST64 *idl, uint64_t idx)
int GWEN_IdList64_DecIdCounter(GWEN_SIMPLEPTRLIST *pl)
static int64_t GWEN_IdList64_AddTable(GWEN_IDLIST64 *idl, GWEN_IDTABLE64 *t)
static int __compDescending(const void *pa, const void *pb)
static GWEN_IDTABLE64 * GWEN_IdTable64_Create(uint64_t maxEntries)
uint64_t GWEN_IdList64_GetUsedTables(const GWEN_IDLIST64 *idl)
uint64_t GWEN_IdList64_GetEntryCount(const GWEN_SIMPLEPTRLIST *pl)
GWEN_IDLIST64_ITERATOR * GWEN_IdList64_Iterator_new(const GWEN_IDLIST64 *idl)
static uint64_t GWEN_IdTable64_GetHighestEntry(const GWEN_IDTABLE64 *ft)
static int __compAscending(const void *pa, const void *pb)
int GWEN_IdList64_HasId(const GWEN_IDLIST64 *idl, uint64_t wantedId)
static uint32_t GWEN_IdTable64_GetRuntimeFlags(const GWEN_IDTABLE64 *ft)
static GWEN_IDTABLE64 * GWEN_IdTable64_new()
static GWENHYWFAR_CB void _detachFromTable(GWEN_SIMPLEPTRLIST *pl, void *p)
void GWEN_IdList64_Clear(GWEN_IDLIST64 *idl)
GWEN_IDLIST64 * GWEN_IdList64_LazyCopy(GWEN_IDLIST64 *oldList)
struct GWEN_IDLIST64_ITERATOR GWEN_IDLIST64_ITERATOR
GWEN_SIMPLEPTRLIST GWEN_IDLIST64
#define GWEN_FREE_OBJECT(varname)
#define GWEN_NEW_OBJECT(typ, varname)
uint64_t GWEN_SimplePtrList_GetUsedEntries(const GWEN_SIMPLEPTRLIST *pl)
GWEN_SIMPLEPTRLIST_ATTACHOBJECT_FN GWEN_SimplePtrList_SetAttachObjectFn(GWEN_SIMPLEPTRLIST *pl, GWEN_SIMPLEPTRLIST_ATTACHOBJECT_FN fn)
int GWEN_SimplePtrList_GetUserIntData(const GWEN_SIMPLEPTRLIST *pl)
int GWEN_SimplePtrList_EnsureWritability(GWEN_SIMPLEPTRLIST *pl)
void GWEN_SimplePtrList_Attach(GWEN_SIMPLEPTRLIST *pl)
void GWEN_SimplePtrList_SetUserIntData(GWEN_SIMPLEPTRLIST *pl, int i)
int GWEN_SimplePtrList_DecUserCounter(GWEN_SIMPLEPTRLIST *pl)
void GWEN_SimplePtrList_free(GWEN_SIMPLEPTRLIST *pl)
int64_t GWEN_SimplePtrList_AddPtr(GWEN_SIMPLEPTRLIST *pl, void *p)
GWEN_SIMPLEPTRLIST_FREEOBJECT_FN GWEN_SimplePtrList_SetFreeObjectFn(GWEN_SIMPLEPTRLIST *pl, GWEN_SIMPLEPTRLIST_FREEOBJECT_FN fn)
uint64_t GWEN_SimplePtrList_GetUserCounter(const GWEN_SIMPLEPTRLIST *pl)
int GWEN_SimplePtrList_SetPtrAt(GWEN_SIMPLEPTRLIST *pl, uint64_t idx, void *p)
void GWEN_SimplePtrList_AddFlags(GWEN_SIMPLEPTRLIST *pl, uint32_t f)
void GWEN_SimplePtrList_SetUserCounter(GWEN_SIMPLEPTRLIST *pl, uint64_t i)
void GWEN_SimplePtrList_Clear(GWEN_SIMPLEPTRLIST *pl)
GWEN_SIMPLEPTRLIST * GWEN_SimplePtrList_LazyCopy(GWEN_SIMPLEPTRLIST *oldList)
GWEN_SIMPLEPTRLIST * GWEN_SimplePtrList_new(uint64_t startEntries, uint64_t steps)
void * GWEN_SimplePtrList_GetPtrAt(const GWEN_SIMPLEPTRLIST *pl, uint64_t idx)
void GWEN_SimplePtrList_IncUserCounter(GWEN_SIMPLEPTRLIST *pl)
struct GWEN_SIMPLEPTRLIST GWEN_SIMPLEPTRLIST
#define GWEN_SIMPLEPTRLIST_FLAGS_ATTACHTOOBJECTS
#define GWEN_SIMPLEPTRLIST_FLAGS_DETACHFROMOBJECTS