Skip to content
Permalink
master
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
// returns index
#define _SEG_ARR_FREE_LIST_ADD_VALIDLIST(type, value_seg) \
do{\
if(!FREESEG_LIST(type)){ \
FREESEG_LIST(type) = _FreeSegNodeMalloc(); \
/*assert(FREESEG_LIST(type) != NULL );*/ \
FREESEG_LIST(type)->next = NULL; \
FREESEG_LIST(type)->index = (value_seg).index; \
} else{ \
TEMP_FREESEGNODE_1(type) = _FreeSegNodeMalloc(); \
/*assert(pTempFreeNode1 != NULL );*/ \
TEMP_FREESEGNODE_1(type)->next = FREESEG_LIST(type); \
FREESEG_LIST(type) = TEMP_FREESEGNODE_1(type); \
FREESEG_LIST(type)->index = ((value_seg).index) ; \
} \
}while(0);
// Algorithm:
// If (an invalid node exists) Then
// move it to the front of valid list
// set its index as the index of value_seg
// Else
// Allocate new node in the valid list
//
#define _SEG_ARR_FREE_LIST_ADD(type, value_seg) do{\
/* check if we already have some previously-allocated memory */ \
if( FREESEG_INVALID_LIST(type) ) {\
/* yes */ \
_SEG_ARR_MOVE_LIST_HEAD( FREESEG_INVALID_LIST(type), FREESEG_LIST(type) ); \
FREESEG_LIST(type)->index = (value_seg).index ; \
} \
else{\
_SEG_ARR_FREE_LIST_ADD_VALIDLIST(type, value_seg); \
} \
}while(0)
#define _SEG_ARR_REMOVE_LIST_HEAD(type, list) (\
TEMP_FREESEGNODE_1(type) = list, \
list = list->next, \
FREE_SAFE( TEMP_FREESEGNODE_1(type) ) )\
// Algorithm:
// If (a valid node exists) Then
// output its index, and
// move it to the front of invalid list
// so that we can reuse its allocated-memory later
// Else
// output null index
//
#define _SEG_ARR_FREE_LIST_GRAB_INDEX(type, value_seg) do{\
if( FREESEG_LIST(type) ) {\
(value_seg).index = FREESEG_LIST(type)->index; \
(value_seg).nextIndex = EMPTY_INDEX; \
_SEG_ARR_MOVE_LIST_HEAD( FREESEG_LIST(type), FREESEG_INVALID_LIST(type) ); \
}else{ \
MAKE_DYNARR_SEG_NULL(value_seg); \
} \
}while(0)
#define _SEG_ARR_FREE_LIST_CLEANUP(type) do{\
while( FREESEG_LIST(type) ) {\
_SEG_ARR_REMOVE_LIST_HEAD(type, FREESEG_LIST(type)); \
} \
while( FREESEG_INVALID_LIST(type) ) {\
_SEG_ARR_REMOVE_LIST_HEAD(type, FREESEG_INVALID_LIST(type)); \
} \
}while(0)
#define _SEG_ARR_HAS_FREE_SEG(type) (FREESEG_LIST(type) != NULL)