Ejemplo n.º 1
0
node *findByValue(node *tree,int value){
	int i;
	node *found = NULL;
	if(!tree){
		return NULL;
	}
	if(tree -> value == value)
		return tree;
	if((found = findByValue(tree -> firstChild, value)))
		return found;
	while(tree -> nextSibling)
		if((found = findByValue(tree -> nextSibling, value))) return found;
	return NULL;
}
Ejemplo n.º 2
0
/**
 * Return the index for a target item.
 *
 * @param target The target object.
 *
 * @return The tail name for the match, or .nil if it was not found.
 */
RexxObject *StemClass::index(RexxInternalObject *target)
{
    CompoundTableElement *variable = findByValue(target);
    if (variable != OREF_NULL)
    {
        return variable->getName();
    }
    return TheNilObject;
}
Ejemplo n.º 3
0
/**
 * Remove an item from the collection.
 *
 * @param target The object of interest.
 *
 * @return .true if the object is in the collection, .false otherwise.
 */
RexxInternalObject *StemClass::removeItem(RexxInternalObject *target)
{
    CompoundTableElement *compound = findByValue(target);
    // if there's a variable there, and it has a real value, then
    // we have something to remove
    if (compound != OREF_NULL && compound->getVariableValue() != OREF_NULL)
    {
        // get the value, which is the return value, and drop the variable.
        RexxInternalObject *oldValue = compound->getVariableValue();
        compound->drop();
        return oldValue;
    }
    return TheNilObject;       // nothing dropped.
}
Ejemplo n.º 4
0
/**
 * Search for any index that matches the target object.
 *
 * @param target The object of interest.
 *
 * @return .true if the object is in the collection, .false otherwise.
 */
RexxObject *StemClass::hasItem(RexxInternalObject *target)
{
    CompoundTableElement *variable = findByValue(target);
    return booleanObject(variable != OREF_NULL);
}