Skip to content
Permalink
b5fa1b28a8
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
110 lines (94 sloc) 4.68 KB
/* The segment structure. These are the nodes of the linked list */
#define DYNARR_SEG_TYPE(type) TYPED_NAME(type, Sseg)
typedef struct {
int index; // my position
int nextIndex; // next node's position
DYNARR_DATA_TYPE data;
}DYNARR_SEG_TYPE(DYNARR_DATA_TYPE);
// true if the index is 0
#define DYNARR_SEG_NULL(value_seg) ( (value_seg).index == EMPTY_INDEX )
#define DYNARR_SEG_NOT_NULL(value_seg) ( (value_seg).index != EMPTY_INDEX )
#define MAKE_DYNARR_SEG_NULL(value_seg) ( (value_seg).index = EMPTY_INDEX )
/* The dynamic array data structure */
#define DYNARR_STATE(type) TYPED_NAME(type, DynArr)
typedef struct{
////////// meta ////////////
// must be 1 after init, 0 after cleanup, 0 before init
int bInitializedFlag;
////////// basics //////////
//unsigned int MaxSeg;
/* Base-2 log */
unsigned int LogMaxSeg;
/* MAXSEG-1; MAXSEG must be a power of 2 */
unsigned int MaxSegRemainderBitMask;
DYNARR_SEG_TYPE(DYNARR_DATA_TYPE)* pSegArr;
//real_t* pSegNextArr;
int iInsertPos;
/////////////////// Free nodes list ////////////////
struct FreeSegNode *pFreeSegList, *pFreeSegInvalidList;
int iSizeOfFreeSegList;
struct FreeSegNode* pTempFreeNode1, *pTempFreeNode2;
////////////// temporaries //////////////
int iTempIndex1, iTempIndex2;
DYNARR_SEG_TYPE(DYNARR_DATA_TYPE) tempSeg1;
DYNARR_SEG_TYPE(DYNARR_DATA_TYPE) emptySeg;
//////////// Segment banks ////////////
DYNARR_SEG_TYPE(DYNARR_DATA_TYPE)** pSegBanksArr;
int* pSegBankSizeArr;
int* pSegBankIndexLimitArr;
int NumSegBanks;
int MaxSegBanks;
int SegBankAllocViolation;
int TotalSegs;
} DYNARR_STATE(DYNARR_DATA_TYPE);
#pragma message(TO_STRING(DYNARR_STATE(DYNARR_DATA_TYPE)))
// dynarr variable name; contains all state variables
#define DYNARR_VARS(type) TYPED_NAME(type, Vars)
/* Declare state variables to be used by functions below */
// SEG_ARR_USE(DYNARR_DATA_TYPE);
/* Shortcuts to important variables */
#define INITIALIZED_FLAG(type) MEMBER(DYNARR_VARS(type),.,bInitializedFlag)
#pragma message(TO_STRING(INITIALIZED_FLAG(DYNARR_DATA_TYPE)))
#define LOGMAXSEG(type) MEMBER(DYNARR_VARS(type),.,LogMaxSeg)
#pragma message(TO_STRING(LOGMAXSEG(DYNARR_DATA_TYPE)))
#define MAXSEG_REMAINDER_BITMASK(type) MEMBER(DYNARR_VARS(type),.,MaxSegRemainderBitMask)
#pragma message(TO_STRING(MAXSEG_REMAINDER_BITMASK(DYNARR_DATA_TYPE)))
#define SEG_ARR(type) MEMBER(DYNARR_VARS(type),.,pSegArr)
#pragma message(TO_STRING(SEG_ARR(DYNARR_DATA_TYPE)))
#define SEG_INSERT_POS(type) MEMBER(DYNARR_VARS(type),.,iInsertPos)
#pragma message(TO_STRING(SEG_INSERT_POS(DYNARR_DATA_TYPE)))
#define FREESEG_LIST(type) MEMBER(DYNARR_VARS(type),.,pFreeSegList)
#pragma message(TO_STRING(FREESEG_LIST(DYNARR_DATA_TYPE)))
#define FREESEG_INVALID_LIST(type) MEMBER(DYNARR_VARS(type),.,pFreeSegInvalidList)
#pragma message(TO_STRING(FREESEG_INVALID_LIST(DYNARR_DATA_TYPE)))
#define FREESEG_LIST_SIZE(type) DYNARR_VARS(type).iSizeOfFreeSegList
#pragma message(TO_STRING(FREESEG_LIST_SIZE(DYNARR_DATA_TYPE)))
#define TEMP_FREESEGNODE_1(type) DYNARR_VARS(type).pTempFreeNode1
#pragma message(TO_STRING(TEMP_FREESEGNODE_1(DYNARR_DATA_TYPE)))
#define TEMP_FREESEGNODE_2(type) DYNARR_VARS(type).pTempFreeNode2
#pragma message(TO_STRING(TEMP_FREESEGNODE_2(DYNARR_DATA_TYPE)))
#define TEMP_INDEX_1(type) MEMBER(DYNARR_VARS(type),.,iTempIndex1)
#pragma message(TO_STRING(TEMP_INDEX_1(DYNARR_DATA_TYPE)))
#define TEMP_INDEX_2(type) MEMBER(DYNARR_VARS(type),.,iTempIndex2)
#pragma message(TO_STRING(TEMP_INDEX_2(DYNARR_DATA_TYPE)))
#define TEMP_SEG_1(type) MEMBER(DYNARR_VARS(type),.,tempSeg1)
#pragma message(TO_STRING(TEMP_SEG_1(DYNARR_DATA_TYPE)))
#define NULL_SEG(type) MEMBER(DYNARR_VARS(type),.,emptySeg)
#pragma message(TO_STRING(NULL_SEG(DYNARR_DATA_TYPE)))
#define TOTAL_SEGS(type) MEMBER(DYNARR_VARS(type),.,TotalSegs)
#pragma message(TO_STRING(SEG_INSERT_POS(DYNARR_DATA_TYPE)))
#define SEG_BANK_ALLOC_VIOLATION(type) MEMBER(DYNARR_VARS(type),.,SegBankAllocViolation)
#pragma message(TO_STRING(SEG_INSERT_POS(DYNARR_DATA_TYPE)))
// maximum number of segment banks
// this should be a very big number
// this number should never be reached
#define MAX_SEG_BANKS(type) MEMBER(DYNARR_VARS(type),.,MaxSegBanks)
// array containing size (# of segments) of each segment bank
#define SEG_BANK_SIZE_ARR(type) MEMBER(DYNARR_VARS(type),.,pSegBankSizeArr)
// array containing last valid index of each segment bank
#define SEG_BANK_INDEX_LIMIT_ARR(type) MEMBER(DYNARR_VARS(type),.,pSegBankIndexLimitArr)
// Number of active segment banks
#define NUM_SEG_BANKS(type) MEMBER(DYNARR_VARS(type),.,NumSegBanks)
#define CURRENT_SEG_BANK(type) (NUM_SEG_BANKS(type) - 1)
// actual segment banks
#define SEG_BANKS_ARR(type) MEMBER(DYNARR_VARS(type),.,pSegBanksArr)