Exemple #1
0
/* ---------------------------------------------------------------------------------
*  LEdgeInfo_NewCustom
*  ---------------------------------------------------------------------------------
*  Constructor for a user defined type */
LEdgeInfo* LEdgeInfo_NewCustom(LGraph* inGraph, ui4 inItemSize)
{
	LEdgeInfo theObject = {0};
	LEdgeInfo* theEdgeInfo = NULL;
	ui4 theCount;
	LException* theException;

    if (inGraph == NULL) Throw(LEdgeInfo_GRAPH_NULL_POINTER);

	Try
	{
		theObject.mData     = LArray_New(inItemSize);
		theObject.mGraph    = inGraph;
		theEdgeInfo = LMemory_NewObject(LEdgeInfo, theObject);
		theCount = LGraph_GetEdgesCount(inGraph);
		LArray_ResizeBy(theEdgeInfo->mData, theCount);
		theEdgeInfo->mGraphIdx = _LGraph_RegisterEdgeInfo(theEdgeInfo->mGraph, theEdgeInfo);
	}
	Catch(theException)
	{/* if something goes wrong, do cleanup */
		LException_Dump(theException);
		if ( theEdgeInfo != NULL ) 
		{
			if ( theEdgeInfo->mData != NULL ) LArray_Delete( &(theEdgeInfo->mData) );
			LMemory_DeleteObject(&theEdgeInfo);
		}
	}
	return theEdgeInfo;
}
Exemple #2
0
/* ---------------------------------------------------------------------------------
 *  CloseBlock
 * ---------------------------------------------------------------------------------
*/
void LSystem_CloseBlock(i1** outBlock,ui4* outSize){
    ui4 theItemsCount;
    _TStackEntry theEntry;
    if (sStack==NULL) Throw(LSystem_INTERNAL_ERROR);
    theItemsCount = LArray_GetItemsCount(sStack);
    if (theItemsCount==0) Throw(LSystem_INTERNAL_ERROR);

    LArray_FetchItemAt(sStack,theItemsCount-1,&theEntry);
    LArray_RemoveLastItem(sStack);
    *outSize = LArray_GetItemsCount(theEntry.mBlock);
    *outBlock = (i1*)LMemory_Malloc(*outSize);
    LMemory_Copy(LArray_GetData(theEntry.mBlock),(void*)*outBlock,*outSize);
    LArray_Delete(&theEntry.mBlock);
    sPrintH = theEntry.mPrintH;

    if (theItemsCount==1) LArray_Delete(&sStack);
}
Exemple #3
0
/* ---------------------------------------------------------------------------------
 *  OpenBlock
 * ---------------------------------------------------------------------------------
*/
void LSystem_OpenBlock(){
    _TStackEntry theEntry = { 0 };
    Try {
        if (sStack==NULL) 
            sStack = LArray_New(sizeof(_TStackEntry));
        theEntry.mPrintH = sPrintH;
        theEntry.mBlock = LArray_New(1);
        LArray_AppendItem(sStack,&theEntry);
        sPrintH = (LSystem_THandler)_PrintH;
    }
    CatchAny {
        if (theEntry.mBlock!=NULL) LArray_Delete(&theEntry.mBlock);
        if (sStack!=NULL && LArray_GetItemsCount(sStack)==0)
            LArray_Delete(&sStack);
        Rethrow;
    }
}
Exemple #4
0
void LQuickFind_Delete (LQuickFind** ThisA)
{
	LArray* theItems;
	ui4 theNumItems;
	ui4 i;
	LArray** theTreePtr;	
	LHash* theTmpHashTable;
	
	/*creates tmp hash table...*/
	theTmpHashTable=LHash_New ();

	/*retrieves pointers to all trees (larrays)...*/
	theItems=LHash_GetAllItems ((*ThisA)->mHashTable);
	
	/*deletes all larrays...*/
	theNumItems=LArray_GetItemsCount (theItems);
	for (i=0; i<theNumItems; i++)
	{
		/*retrieves pointer to tree...*/
		theTreePtr=(LArray **)LArray_ItemAt (theItems, i);
		/*if not in tmp hash table...*/
		if (!LHash_IsInTable (theTmpHashTable, (ui4)*theTreePtr))
		{
			/*insert in tmp hash table...*/
			LHash_InsertItem (theTmpHashTable, NULL, (ui4)*theTreePtr);
			/*delete tree...*/
			LArray_Delete (theTreePtr);
		}		
	}
	
	/*deletes tmp hash table...*/
	LHash_Delete (&theTmpHashTable);
	
	/*must be manually deleted...*/
	LArray_Delete (&theItems);
	
	/*deletes hash table...*/
	LHash_Delete (&((*ThisA)->mHashTable));
		
	/*deletes object...*/
	LMemory_DeleteObject (ThisA);
}
Exemple #5
0
/* ---------------------------------------------------------------------------------
*  LEdgeInfo_Delete
*  ---------------------------------------------------------------------------------
*  Destructor */
void LEdgeInfo_Delete(LEdgeInfo** ThisA)
{
	LException* theException;
        
    if (ThisA == NULL) Throw(LEdgeInfo_OBJECT_NULL_POINTER);
    if ((*ThisA) == NULL) Throw(LEdgeInfo_OBJECT_NULL_POINTER);

	_LEdgeInfo_CallItemsDestructor((*ThisA));
		
	Try
		LArray_Delete( &( (*ThisA)->mData ) );
	Catch(theException)
		LException_Dump(theException);
	LMemory_DeleteObject(ThisA);
}
Exemple #6
0
/* ---------------------------------------------------------------------------------
*  LQuickFind_GetUsedMem
*  ---------------------------------------------------------------------------------
*  GetUsedMem */
ui4 LQuickFind_GetUsedMem (LQuickFind* This)
{
	ui4 theHashTableUsedMem=0;
	ui4 theQuickFindStructUsedMem=0;
	ui4 theLArraysUsedMem=0;
	
	LArray* theItems;
	ui4 theNumItems;
	LArray** theTreePtr;
	ui4 i;
	LHash* theTmpHashTable;
	
	/*creates tmp hash table...*/
	theTmpHashTable=LHash_New ();
	
	/*size of hash table...*/
	theHashTableUsedMem=LHash_GetUsedMem (This->mHashTable);
	
	/*size of struct LQuickFind...*/
	theQuickFindStructUsedMem=sizeof (struct LQuickFind);
	
	/*size of all larrays...*/
	theItems=LHash_GetAllItems (This->mHashTable);
	theNumItems=LArray_GetItemsCount (theItems);
	for (i=0; i<theNumItems; i++)
	{	
		/*retrieves pointer to tree...*/
		theTreePtr=(LArray **)LArray_ItemAt (theItems, i);
		/*if not in tmp hash table...*/
		if (!LHash_IsInTable (theTmpHashTable, (ui4)*theTreePtr))
		{
			/*insert in tmp hash table...*/
			LHash_InsertItem (theTmpHashTable, NULL, (ui4)*theTreePtr);
			/*take size into account...*/
			theLArraysUsedMem=theLArraysUsedMem + LArray_GetUsedMem(*theTreePtr);
		}	
	}
	
	/*deletes tmp hash table...*/
	LHash_Delete (&theTmpHashTable);
	
	/*must be manually deleted...*/
	LArray_Delete (&theItems);
		
	return (theHashTableUsedMem + theQuickFindStructUsedMem + theLArraysUsedMem);
}
Exemple #7
0
/* ---------------------------------------------------------------------------------
*  LQuickFind_Union
*  ---------------------------------------------------------------------------------
*  Union */
ui4 LQuickFind_Union (LQuickFind* This, ui4 inItem1, ui4 inItem2)
{
	ui4 thelength1, thelength2;
	LArray *thelarray1, *thelarray2;
	ui4 i;
	ui4 *thecur_item;
	ui4 theset1, theset2;
	
	void *theSource, *theDest;
	
#if LQuickFind_STATS
	/*updates stats...*/
	This->mNumUnions++;
#endif
	
	/*parameter checking...*/
	if ((inItem1==LQuickFind_BAD_ITEM) || (inItem2==LQuickFind_BAD_ITEM))
		return LQuickFind_BAD_ITEM;
	
	theset1=LQuickFind_Find (This, inItem1);
	theset2=LQuickFind_Find (This, inItem2);

	/*if either set doesn't exist...*/
	if ((theset1==LQuickFind_BAD_ITEM) || (theset2==LQuickFind_BAD_ITEM))
		return LQuickFind_BAD_ITEM; /*returns an invalid id...*/
		
	/*if already in same set...*/
	if (theset1==theset2)
		return theset1; //nothing to do...
	
	/*retrieves 1st tree (LArray)...*/
	thelarray1=(LArray *)LHash_GetItemByKey (This->mHashTable, inItem1);
	
	/*retrieves 2nd tree (LArray)...*/
	thelarray2=(LArray *)LHash_GetItemByKey (This->mHashTable, inItem2);
	
	/*gets lengths...*/
	thelength1=LArray_GetItemsCount (thelarray1);
	thelength2=LArray_GetItemsCount (thelarray2);
	/*performs (balanced) union...*/
	if (thelength1 >= thelength2)
	{
		/*resizes larray1...*/
		LArray_ResizeBy (thelarray1, thelength2);
		/*gets address of first item of larray2...*/
		theSource=LArray_ItemAt (thelarray2, 0);
		/*gets first empty slot in larray1...*/
		theDest=LArray_ItemAt (thelarray1, thelength1);
		/*copies larray2 onto larray1...*/
		LMemory_Copy (theSource, theDest, thelength2*4);
		
#if LQuickFind_STATS
		/*updates stats...*/
		This->mItemsMovedByUnions=This->mItemsMovedByUnions+thelength2;
#endif
		
		for (i=0; i<thelength2; i++)
		{
			thecur_item=(ui4 *)LArray_ItemAt (thelarray2, i);
			//LArray_AppendItem (thelarray1, thecur_item);
			/*replaces item in hash table...*/
			//LHash_InsertItem (This->mHashTable, (void *)thelarray1, *thecur_item);
			LHash_ReplaceItemByKey (This->mHashTable, *thecur_item, (void *)thelarray1);
		}	
		LArray_Delete (&thelarray2);
	}
	else
	{
		/*renames tree as well...*/
		thecur_item=(ui4 *)LArray_ItemAt (thelarray1, 0);
		LArray_InsertItemAt (thelarray2, thecur_item, 0);
		/*replaces item in hash table...*/
		LHash_InsertItem (This->mHashTable, (void *)thelarray2, *thecur_item);
		
		if (thelength1>1)
		{
			/*resizes larray2...*/
			LArray_ResizeBy (thelarray2, thelength1-1);
			/*gets address of second item of larray1...*/
			theSource=LArray_ItemAt (thelarray1, 1);
			/*gets first empty slot in larray1...*/
			theDest=LArray_ItemAt (thelarray2, thelength2+1);
			/*copies larray1 onto larray2...*/
			LMemory_Copy (theSource, theDest, (thelength1-1)*4);
		}
		
#if LQuickFind_STATS
		/*updates stats...*/
		This->mItemsMovedByUnions=This->mItemsMovedByUnions+thelength1;
#endif
		
		for (i=1; i<thelength1; i++)
		{
			thecur_item=(ui4 *)LArray_ItemAt (thelarray1, i);
			//LArray_AppendItem (thelarray2, thecur_item);
			/*replaces item in hash table...*/
			//LHash_InsertItem (This->mHashTable, (void *)thelarray2, *thecur_item);
			LHash_ReplaceItemByKey (This->mHashTable, *thecur_item, (void *)thelarray2);
		}
		LArray_Delete (&thelarray1);
	}

	/*returns appropriate set name...*/
	if (thelength1 >= thelength2)
		return theset1;
	else
		return theset2;
}