Exemplo n.º 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;
}
Exemplo n.º 2
0
void LArray_RemoveItemAt(LArray* This, ui4 inIndex){

    /* Range check */
    if (inIndex>=This->mItemsCount) Throw(LArray_OUT_OF_RANGE);

    /* Scroll items with indices > inIndex */
    LMemory_Move(This->mData + (inIndex+1) * This->mItemSize,
                 This->mData + (inIndex)   * This->mItemSize,
                 This->mItemSize * (This->mItemsCount -1 -inIndex));

    /* Shrink the array */
    LArray_ResizeBy(This,-1);
}
Exemplo n.º 3
0
static void _PrintH(const i1* inMsg){
    ui4 theCount, theMsgLen, thePrevBlockLen;
    _TStackEntry theEntry;
    if (sStack==NULL) Throw(LSystem_INTERNAL_ERROR);
    theCount = LArray_GetItemsCount(sStack);
    if (theCount==0) Throw(LSystem_INTERNAL_ERROR);
    LArray_FetchItemAt(sStack,theCount-1,&theEntry);
    theMsgLen = LString_Len(inMsg);
    thePrevBlockLen = LArray_GetItemsCount(theEntry.mBlock);
    LArray_ResizeBy(theEntry.mBlock,(i4)theMsgLen);
    LMemory_Copy(inMsg,
        (i1*)LArray_GetData(theEntry.mBlock)+thePrevBlockLen,
        theMsgLen);
}
Exemplo n.º 4
0
/* ---------------------------------------------------------------------------------
*  _LEdgeInfo_AddInfo();
*  ---------------------------------------------------------------------------------
*  Makes room for a new info in the Edge */
void _LEdgeInfo_AddInfo(LEdgeInfo* This, LGraph_TEdge* inEdge)
{ 
	LException* theException;
	
    if (This == NULL) Throw(LEdgeInfo_OBJECT_NULL_POINTER);

	Try
		LArray_ResizeBy(This->mData, 1); 
	Catch(theException)
		LException_Dump(theException);
	/* if the newHandler has been registered, call it */
	if (This->mAlloc)
		(*(This->mAlloc))(This, inEdge);

}
Exemplo n.º 5
0
void LArray_InsertItemAt(LArray* This, const void* inItem, ui4 inIndex){

    /* Range adjustment */
    if (inIndex > This->mItemsCount) inIndex = This->mItemsCount;

    /* Make room for the new entry */
    LArray_ResizeBy(This,+1);

    /* Scroll items with indices > inIndex */
    if (This->mItemsCount -1 -inIndex > 0)
        LMemory_Move(This->mData + (inIndex)  * This->mItemSize,
                    This->mData + (inIndex+1) * This->mItemSize,
                    This->mItemSize * (This->mItemsCount -1 -inIndex));

    /* Assign the new entry */
    LMemory_Copy(inItem, This->mData+(inIndex)*This->mItemSize, This->mItemSize);
}
Exemplo n.º 6
0
ui4 LArray_AppendItem(LArray* This, const void* inItem){

    /* Make room for the new entry */
    LArray_ResizeBy(This,+1);

    /* Copy the input item at the end of the array */
    if (This->mItemSize == 4) 
        _ui4_(This->mData+(This->mItemsCount-1)*This->mItemSize) = _ui4_(inItem);
    else 
        LMemory_Copy(inItem, This->mData+(This->mItemsCount-1)*This->mItemSize, This->mItemSize);

    #ifdef TRACE_OPERATIONS_
        LSystem_Print("LArray_AppendItem [This->mData size=%u, This->mItemsCount=%u]\n",
                      This->mDataSize,This->mItemsCount);
    #endif

    /* Return the index of added item */
    return This->mItemsCount-1;
}
Exemplo n.º 7
0
/* ---------------------------------------------------------------------------------
*  _LEdgeInfo_DeleteItemAt
*  ---------------------------------------------------------------------------------
*  Delete the info of a specified Edge*/
void _LEdgeInfo_DeleteItemAt(LEdgeInfo* This, LGraph_TEdge* inEdge) 
{
	LException* theException;
	ui4 theIndex;

    if (This == NULL) Throw(LEdgeInfo_OBJECT_NULL_POINTER);

	/* if installed, calls the destructor handler */
	if (This->mDealloc)
		(*(This->mDealloc))(This, inEdge);

	theIndex = inEdge->mIndex;
    LMemory_Copy(LArray_LastItem(This->mData),
                  LArray_ItemAt(This->mData, theIndex),
                  LArray_GetItemSize(This->mData));
	Try
		LArray_ResizeBy(This->mData, -1);
	Catch(theException)
		LException_Dump(theException);
}
Exemplo n.º 8
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;
}