예제 #1
0
int OsContact::compareTo(UtlContainable const * inVal) const
{
    int result ; 
   
    const OsContact* pContact = static_cast<const OsContact*>(inVal);
    if (inVal->isInstanceOf(OsContact::TYPE) && pContact)
    {
        UtlString address;
        pContact->getAddress(address);
        result = mAddress.compareTo(address);
        if (0 == result)
        {
            result = compareInt(mPort, pContact->getPort());
        }
        if (0 == result)
        {
            result = compareInt(mProtocol, pContact->getProtocol());
        }
        if (0 == result)
        {
            result = compareInt((const int)mType, (const int)pContact->getAddressType());
        }
    }
    else
    {
        result = INT_MAX ; 
    }

    return result ;
}
예제 #2
0
int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) {
    if (LHS.getNameKind() != RHS.getNameKind())
        return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1);

    switch (LHS.getNameKind()) {
    case DeclarationName::Identifier: {
        IdentifierInfo *LII = LHS.getAsIdentifierInfo();
        IdentifierInfo *RII = RHS.getAsIdentifierInfo();
        if (!LII) return RII ? -1 : 0;
        if (!RII) return 1;

        return LII->getName().compare(RII->getName());
    }

    case DeclarationName::ObjCZeroArgSelector:
    case DeclarationName::ObjCOneArgSelector:
    case DeclarationName::ObjCMultiArgSelector: {
        Selector LHSSelector = LHS.getObjCSelector();
        Selector RHSSelector = RHS.getObjCSelector();
        unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
        for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
            switch (LHSSelector.getNameForSlot(I).compare(
                        RHSSelector.getNameForSlot(I))) {
            case -1:
                return true;
            case 1:
                return false;
            default:
                break;
            }
        }

        return compareInt(LN, RN);
    }

    case DeclarationName::CXXConstructorName:
    case DeclarationName::CXXDestructorName:
    case DeclarationName::CXXConversionFunctionName:
        if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType()))
            return -1;
        if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType()))
            return 1;
        return 0;

    case DeclarationName::CXXOperatorName:
        return compareInt(LHS.getCXXOverloadedOperator(),
                          RHS.getCXXOverloadedOperator());

    case DeclarationName::CXXLiteralOperatorName:
        return LHS.getCXXLiteralIdentifier()->getName().compare(
                   RHS.getCXXLiteralIdentifier()->getName());

    case DeclarationName::CXXUsingDirective:
        return 0;
    }

    return 0;
}
예제 #3
0
int TaskCompare::compare(Task *const &pt1, Task *const &pt2)
{
	// result's intent is to catch a definitive: less than or more
	// it is important for sortable containers to avoid zero (0)
	// as zero represents equality
	//TODO: review for means of generic extensible implementation
    int result = 0;
    int sortLvl = 0;
    do
    {
        switch(m_pFields[sortLvl])
        {
		case COMPARE_TASK_ID:
			result = compareDate(pt1->GetID(), pt2->GetID());
			break;
        case COMPARE_DUE_DATE:
            result = compareDate(pt1->GetDueDate(), pt2->GetDueDate());
            break;
        case COMPARE_PRIORITY:
            result = compareInt(pt1->GetPriority(), pt2->GetPriority());
            break;
		//case COMPARE_PERCENT_COMPLETE:
		//	result = compareInt(pt1->getPercentComplete(), pt2->getPercentComplete());
		//	break;
        case COMPARE_CREATE_DATE:
            result = compareDate(pt1->GetCreatedDate(), pt2->GetCreatedDate());
            break;
		case COMPARE_ESTIMATED_DURATION:
			result = compareDate(pt1->GetEstimatedDuration(), pt2->GetEstimatedDuration());
			break;
		case COMPARE_START_DATE:
			result = compareDate(pt1->GetScheduledStart(), pt2->GetScheduledStart());
			break;
		case COMPARE_TASK_TITLE:
			result = compareText(pt1->GetTitle(), pt2->GetTitle());
			break;
        default:
            break;
        }
        ++sortLvl;
    }
    while(!result && sortLvl < m_numSortLvls);
	if(!result)result = compareDate(pt1->GetID(), pt2->GetID());
    return result;
}
예제 #4
0
파일: sortTest.c 프로젝트: SanggyuLee/rtos
A_Test void whenComparingTwoAndOne_thenReturnsPositiveNumber(void)
{
    int n1 = 2;
    int n2 = 1;
    assertTrueM("Comparing 2 with 1 must return a value >0.", compareInt(&n1, &n2) > 0);
}
예제 #5
0
파일: sortTest.c 프로젝트: SanggyuLee/rtos
A_Test void whenComparingOneAndTwo_thenReturnsNegativeNumber(void)
{
    int n1 = 1;
    int n2 = 2;
    assertTrueM("Comparing 1 with 2 must return a value <0.", compareInt(&n1, &n2) < 0);
}
예제 #6
0
파일: sortTest.c 프로젝트: SanggyuLee/rtos
A_Test void whenComparingZeroAndZero_thenReturnsZero(void)
{
    int n1 = 0;
    int n2 = 0;
    assertEqualsM("Comparing two equal numbers must return 0.", 0, compareInt(&n1, &n2));
}
예제 #7
0
파일: events.c 프로젝트: robotiko/rules
static unsigned int handleAlpha(ruleset *tree, char *sid, char *mid, char *state, alpha *alphaNode, jsonProperty *allProperties, 
                                void **rulesBinding, unsigned short actionType, unsigned short *commandCount) {
    alpha *alphaStack[MAX_STACK_SIZE];
    jsonProperty *propertyStack[MAX_STACK_SIZE];
    alphaStack[0] = alphaNode;    
    propertyStack[0] = NULL;
    alpha *currentAlpha;
    jsonProperty *currentProperty;
    unsigned short top = 1;
    unsigned int result = ERR_EVENT_NOT_HANDLED;
    unsigned int propertyHash = 1;

    while (top > 0) {       
        --top;
        currentAlpha = alphaStack[top];
        currentProperty = propertyStack[top];
        unsigned char alphaOp = currentAlpha->operator;
        unsigned char propertyMatch = 1;
        if (alphaOp != OP_NEX && alphaOp != OP_EX && alphaOp != OP_TYPE)
        {
            char *propertyLast = currentProperty->lastValue;
            char *propertyFirst = currentProperty->firstValue;
            unsigned char propertyType = currentProperty->type;
            char temp;
            if (!currentProperty->isMaterial) {
                switch(propertyType) {
                    case JSON_INT:
                        ++propertyLast;
                        temp = propertyLast[0];
                        propertyLast[0] = '\0';
                        currentProperty->value.i = atol(propertyFirst);
                        propertyLast[0] = temp;
                        break;
                    case JSON_DOUBLE:
                        ++propertyLast;
                        temp = propertyLast[0];
                        propertyLast[0] = '\0';
                        currentProperty->value.i = atof(propertyFirst);
                        propertyLast[0] = temp;
                        break;
                    case JSON_BOOL:
                        ++propertyLast;
                        unsigned int leftLength = propertyLast - propertyFirst;
                        unsigned char b = 1;
                        if (leftLength == 5 && strncmp("false", propertyFirst, 5)) {
                            b = 0;
                        }
                        currentProperty->value.b = b;
                        break;
                }

                currentProperty->isMaterial = 1;
            }
            
            unsigned short type = propertyType << 8;
            type = type + currentAlpha->right.type;
            int leftLength;
            switch(type) {
                case COMP_BOOL_BOOL:
                    propertyMatch = compareBool(currentProperty->value.b, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_BOOL_INT: 
                    propertyMatch = compareInt(currentProperty->value.b, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_BOOL_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.b, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_BOOL_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_INT_BOOL:
                    propertyMatch = compareInt(currentProperty->value.i, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_INT_INT: 
                    propertyMatch = compareInt(currentProperty->value.i, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_INT_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_INT_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_DOUBLE_BOOL:
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_DOUBLE_INT: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_DOUBLE_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_DOUBLE_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_STRING_BOOL:
                    if (currentAlpha->right.value.b) {
                        propertyMatch = compareString(propertyFirst, propertyLast, "true", alphaOp);
                    }
                    else {
                        propertyMatch = compareString(propertyFirst, propertyLast, "false", alphaOp);
                    }
                    break;
                case COMP_STRING_INT: 
                    {
                        leftLength = propertyLast - propertyFirst + 1;
                        char rightStringInt[leftLength];
                        snprintf(rightStringInt, leftLength, "%ld", currentAlpha->right.value.i);
                        propertyMatch = compareString(propertyFirst, propertyLast, rightStringInt, alphaOp);
                    }
                    break;
                case COMP_STRING_DOUBLE: 
                    {
                        leftLength = propertyLast - propertyFirst + 1;
                        char rightStringDouble[leftLength];
                        snprintf(rightStringDouble, leftLength, "%f", currentAlpha->right.value.d);
                        propertyMatch = compareString(propertyFirst, propertyLast, rightStringDouble, alphaOp);
                        break;
                    }
                case COMP_STRING_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
            }
        }

        if (propertyMatch) {
            unsigned int nextLength = currentAlpha->nextLength;
            unsigned int nextOffset = currentAlpha->nextOffset;   
            for (unsigned int i = 0; i < nextLength; ++i) {
                node *currentNode = &tree->nodePool[tree->nextPool[nextOffset + i]];
                unsigned int nodeHash;
                if (currentNode->type != NODE_ALPHA) {
                    result = handleBeta(tree, sid, mid, state, currentNode, rulesBinding, actionType, commandCount);
                }
                else {
                    nodeHash = currentNode->value.a.hash;
                    propertyHash = 1;
                    for (int ii = 0; propertyHash && (propertyHash != nodeHash) && (ii < MAX_CONFLICTS); ++ii) {
                        currentProperty = &allProperties[(nodeHash & HASH_MASK) + (ii * MAX_BUCKET_LENGTH)];
                        propertyHash = currentProperty->hash;
                    }
                    if (((nodeHash == propertyHash) && (currentNode->value.a.operator != OP_NEX)) || 
                        ((nodeHash != propertyHash) && (currentNode->value.a.operator == OP_NEX))) {
                        if (top == MAX_STACK_SIZE) {
                            return ERR_MAX_STACK_SIZE;
                        }

                        alphaStack[top] =  &currentNode->value.a;
                        propertyStack[top] = currentProperty;
                        ++top;
                    }
                }
            }
        }
    }

    return result;
}
예제 #8
0
 int compareInt(uint64_t const a, uint64_t const b) const
 {
     uint8_t const * da = data + a + sizeof(uint32_t);
     uint8_t const * db = data + b + sizeof(uint32_t);
     return compareInt(da,db);
 }
void SoConditionalTrigger::inputChanged(SoField * whichField)
{
    if ((whichField == &token) | (whichField == &triggerAtInit))
    {
        trigger.enable(FALSE);
        tokenOut.enable(FALSE);
        boolOut.enable(FALSE);
		//SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
		//		"%s: token now set to: %s",
		//		this->getName().getString(), token.getValue().getString());
    }
    else {
	    bool localC = true;
        bool any = false;
	    int i,j, num, tnum;

        if (whichField == &triggerIn) {
            any = true;
            triggerNotified = false;
        }

	    // check all conditions.
	    if (((num = boolIn.getNum()) > 0) && ((tnum = triggerBool.getNum()) > 0)){
		    localC = false; any = true;
		    for (i=0; i<num; i++){
                for (j=0; j<tnum; j++){
			        if (boolIn[i] == triggerBool[j]){
				        localC = true;
				        break;
			        }
                }
                if (localC) break;
		    }
	    }

	    if (localC && ((num = floatIn.getNum()) > 0) && (triggerFloat.getNum() > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
			    if (compareFloat(floatIn[i])){
				    localC = true;
				    break;
			    }
		    }
	    }

	    if (localC && ((num = intIn.getNum()) > 0) && (triggerInt.getNum() > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
			    if (compareInt(intIn[i])){
				    localC = true;
				    break;
			    }
		    }
	    }

	    if (localC && ((num = stringIn.getNum()) > 0) && ((tnum = triggerString.getNum()) > 0)) {
		    localC = false; any = true;
            if (comparison.getValue() == EQUAL) {
                for (i=0; i<num; i++){
                    for (j=0; j<tnum; j++){
			            if (stringIn[i] == triggerString[j]){
				            localC = true;
				            break;
			            }
                    }
                    if (localC) break;
		        }
            }
            else {
                for (i=0; i<num; i++){
                    for (j=0; j<tnum; j++){
			            if (! stringIn[i] == triggerString[j]){
				            localC = true;
				            break;
			            }
                    }
                    if (localC) break;
		        }
            }
	    }
        
	    if (localC && ((num = nodeIn.getNum()) > 0) && ((tnum = triggerNode.getNum()) > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
                for (j=0; j<tnum; j++){
			        if (nodeIn[i] == triggerNode[j]){
				        localC = true;
				        break;
			        }
                }
                if (localC) break;
		    }
	    }

        if (!any) localC = false;
                
	    if (localC) {
            if (!retrigger.getValue())
            {
                if (!triggerNotified) {
				    //SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
				    //		"%s: condition == TRUE -> notify trigger!\n",this->getName().getString());
                    boolOut.enable(TRUE);
                    trigger.enable(TRUE);
                    tokenOut.enable(TRUE);
                    triggerNotified = true;
                    tempBool = true;
                }
                else {
                    trigger.enable(FALSE);
                    tokenOut.enable(FALSE);
                }
            }
            else
            {
                boolOut.enable(TRUE);
                trigger.enable(TRUE);
                tokenOut.enable(TRUE);
                triggerNotified = true;
                tempBool = true;
            }
	    }
        else {
            if (tempBool) {
				//SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
				//		"%s: condition == FALSE -> update boolOut!",
				//		this->getName().getString());
                tempBool = false;
                boolOut.enable(TRUE);
            }
            trigger.enable(FALSE);
            tokenOut.enable(FALSE);
            triggerNotified = false;
        }
    }
}
예제 #10
0
파일: AVL.c 프로젝트: soofatt/AVL
/**
 *Description : To remove a node from the AVL tree
 *
 *Inputs : **ptrToRoot -> The pointer to pointer to the root of the current tree
 *         *nodeToRemove -> The node to be removed from the tree
 *
 *Output : returnNode -> The node that is removed
 *
 */
Node *avlRemove(Node **ptrToRoot, Node *nodeToRemove, int (*compare)(void *, void *)){
  Node *returnNode = NULL;
  Node *tempNode;
  int tempBalanceLeft, tempBalanceRight, tempBalanceForReplacement;
  int compareResult;
  
  if((*ptrToRoot) !=NULL){
    compareResult = compareInt((*ptrToRoot), nodeToRemove);
    
    if(compareResult == 0){
      returnNode = (*ptrToRoot);
      tempNode = returnNode;
      
      if((*ptrToRoot)->leftChild == NULL){
        (*ptrToRoot) = (*ptrToRoot)->rightChild;
        
        if((*ptrToRoot) != NULL){
          (*ptrToRoot)->leftChild = tempNode->leftChild;
          (*ptrToRoot)->rightChild = tempNode->rightChild;
          (*ptrToRoot)->balance = tempNode->balance;
          (*ptrToRoot)->balance--;
        }
      }
      
      else{
        tempBalanceForReplacement = (*ptrToRoot)->leftChild->balance;
        (*ptrToRoot) = avlGetReplacer(&(*ptrToRoot)->leftChild);
        
        if((*ptrToRoot) != NULL){
          (*ptrToRoot)->leftChild = tempNode->leftChild;
          (*ptrToRoot)->rightChild = tempNode->rightChild;
          (*ptrToRoot)->balance = tempNode->balance;
          if((*ptrToRoot)->leftChild == NULL)
            (*ptrToRoot)->balance++;
          
          else if((*ptrToRoot)->leftChild->balance == 0){
            if(tempBalanceForReplacement - (*ptrToRoot)->leftChild->balance != 0)
              (*ptrToRoot)->balance++;
            else{}
          }
          
          else{}
        }
      }
    }  
    
    else if(compareResult == 1){
      if((*ptrToRoot)->leftChild != NULL)
        tempBalanceLeft = (*ptrToRoot )->leftChild->balance;
        
      returnNode = avlRemove(&(*ptrToRoot)->leftChild, nodeToRemove, compare);
      
      if(returnNode == NULL)
        return returnNode;
      
      if((*ptrToRoot)->leftChild == NULL)
        (*ptrToRoot)->balance++;
        
      else if((*ptrToRoot)->leftChild->balance == 0){
        if(tempBalanceLeft - (*ptrToRoot)->leftChild->balance != 0)
          (*ptrToRoot)->balance++;
        else {}
      }
      
      else{}
    }
    
    else if(compareResult == -1){
      if((*ptrToRoot)->rightChild != NULL)
        tempBalanceRight = (*ptrToRoot)->rightChild->balance;
      
      returnNode = avlRemove(&(*ptrToRoot)->rightChild, nodeToRemove, compare);
      
      if(returnNode == NULL)
        return returnNode;
      
      if((*ptrToRoot)->rightChild == NULL)
        (*ptrToRoot)->balance--;
      
      else if((*ptrToRoot)->rightChild->balance == 0){
        if(tempBalanceRight - (*ptrToRoot)->rightChild->balance != 0)
          (*ptrToRoot)->balance--;
        else{}
      }
      
      else{}
    }
  }  
    
  if((*ptrToRoot) !=NULL){
    if((*ptrToRoot)->balance == 2 && (*ptrToRoot)->rightChild->balance == 1)
     (*ptrToRoot) = leftRotate((*ptrToRoot));
    else if((*ptrToRoot)->balance == 2 && (*ptrToRoot)->rightChild->balance == 0)
     (*ptrToRoot) = leftRotate((*ptrToRoot));
    else if((*ptrToRoot)->balance == 2 && (*ptrToRoot)->rightChild->balance == -1)
     (*ptrToRoot) = doubleLeftRotate((*ptrToRoot));
    else if((*ptrToRoot)->balance == -2 && (*ptrToRoot)->leftChild->balance == 1)
     (*ptrToRoot) = doubleRightRotate((*ptrToRoot));
    else if((*ptrToRoot)->balance == -2 && (*ptrToRoot)->leftChild->balance == -1)
     (*ptrToRoot) = rightRotate((*ptrToRoot));
    else if((*ptrToRoot)->balance == -2 && (*ptrToRoot)->leftChild->balance == 0)
     (*ptrToRoot) = rightRotate((*ptrToRoot));
    else{}
  }
  
  return returnNode;
}