Esempio n. 1
0
int main() {
  Node tree1[9];
  Node tree2[9];
 
  for(int i = 0; i < 9; i++){
    tree1[i].n = tree2[i].n = i;
    tree1[i].left = tree1[i].right = NULL;
    tree2[i].left = tree2[i].right = NULL;
  }
 
  tree1[0].left = &tree1[1];
  tree1[0].right = &tree1[2];
  tree1[1].left = &tree1[3];
  tree1[1].right = &tree1[4];
  tree1[2].left = &tree1[5];
  tree1[2].right = &tree1[6];
  tree1[4].left = &tree1[7];
  tree1[6].right = &tree1[8];
 
  tree2[0].left = &tree2[1];
  tree2[0].right = &tree2[2];
  tree2[1].left = &tree2[3];
  tree2[1].right = &tree2[4];
  tree2[2].left = &tree2[5];
  tree2[2].right = &tree2[8];
  tree2[4].left = &tree2[6];
  tree2[6].right = &tree2[7];
 
  printf("%d\n", isIdentical(&tree1[0], &tree2[0]));
  printf("%d\n", isIdentical(&tree1[0], &tree1[0]));
  return 0;
}
    /**
     * @aaram a, b, the root of binary trees.
     * @return true if they are identical, or false.
     */
    bool isIdentical(TreeNode* a, TreeNode* b) {
        if (!a && !b) return true;
        if (a && !b || b && !a) return false;
        if (a->val != b->val) return false;

        return isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
    }
Esempio n. 3
0
 /*
  * @param a: the root of binary tree a.
  * @param b: the root of binary tree b.
  * @return: true if they are identical, or false.
  */
 bool isIdentical(TreeNode * a, TreeNode * b) {
     // write your code here
     if(a == NULL && b == NULL)
         return true;
     if(a == NULL || b == NULL)
         return false;
     return a->val == b->val && isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
 }
 /**
  * @aaram a, b, the root of binary trees.
  * @return true if they are identical, or false.
  */
 bool isIdentical(TreeNode* a, TreeNode* b) {
     if(a == nullptr && b == nullptr) return true;
     else if(a == nullptr || b == nullptr) return false;
     else if(a->val != b->val) return false;
     
     return isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
     
 }
Esempio n. 5
0
int isIdentical( struct node *p1, struct node *p2)
{
	if(p1==NULL && p2==NULL)
		return 1;
	if(p1!=NULL && p2!=NULL && p1->info == p2->info)
		if(isIdentical(p1->lchild, p2->lchild) && isIdentical(p1->rchild, p2->rchild))
			return 1;
	return 0;
}
Esempio n. 6
0
main()
{
	struct node *root1=NULL, *root2=NULL,*root3=NULL, *root4=NULL;
	
	root1 = insert(root1, 10);
	root1 = insert(root1, 2);
	root1 = insert(root1, 9);
	root1 = insert(root1, 5);
	
	root2 = insert(root2, 6);
	root2 = insert(root2, 3);
	root2 = insert(root2, 8);
	root2 = insert(root2, 7);
	root2 = insert(root2, 1);
	root2 = insert(root2, 4);
			
	root3 = insert(root3, 16);
	root3 = insert(root3, 13);
	root3 = insert(root3, 18);
	root3 = insert(root3, 17);
	root3 = insert(root3, 11);
	root3 = insert(root3, 14);

	
	if(isSimilar(root1,root2))
		printf("Tree 1 and 2 are Similar\n");
	else
		printf("Tree 1 and 2 are Not Similar\n");

	if(isIdentical(root1,root2))
		printf("Tree 1 and 2 are Identical\n");
	else
		printf("Tree 1 and 2 are Not Identical\n");
	
	if(isSimilar(root2,root3))
		printf("Tree 2 and 3 are Similar\n");
	else
		printf("Tree 2 and 3 are Not Similar\n");

	if(isIdentical(root2,root3))
		printf("Tree 2 and 3 are Identical\n");
	else
		printf("Tree 2 and 3 are Not Identical\n");

	root4=copy_tree(root3);
	if(isSimilar(root3,root4))
		printf("Tree 3 and 4 are Similar\n");
	else
		printf("Tree 3 and 4 are Not Similar\n");

	if(isIdentical(root3,root4))
		printf("Tree 3 and 4 are Identical\n");
	else
		printf("Tree 3 and 4 are Not Identical\n");
}/*End of main( )*/
Esempio n. 7
0
/**
 * @aaram a, b, the root of binary trees.
 * @return true if they are identical, or false.
 */
bool isIdentical(TreeNode* a, TreeNode* b) {
    // Write your code here
    if(a == NULL && b == NULL) {
        return true;
    }
    if(a == NULL && b != NULL || a != NULL && b == NULL) {
        return false;
    }
    if(a->val != b->val) {
        return false;
    }
    return isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
    
}
Esempio n. 8
0
void alignLeft(Aln* aln) {
    aln->identical_group = aln->GAP_CHECK + aln->MISMATCH_CHECK;
    while (anyExists(aln)) {
        if (allExist(aln) && isIdentical(aln)) {
            moveWholeRow(aln);
            aln->identical_group += 1;
        } else {
            int ok = 0;
            if (allExist(aln) && identicalAround(aln,
                        aln->MISMATCH_CHECK)) {
                moveWholeRow(aln);
                ok = 1;
            } else if (identicalLeft(aln, aln->GAP_CHECK)) {
                int* new_used = findBestGap(aln);
                if (new_used) {
                    moveGap(aln, new_used);
                    free(new_used);
                    ok = 1;
                }
            }
            if (!ok) {
                break;
            }
            aln->identical_group = 0;
        }
    }
}
Esempio n. 9
0
doublereal Func1::isProportional(TimesConstant1& other)
{
    if (isIdentical(other.func1())) {
        return other.c();
    }
    return 0.0;
}
Esempio n. 10
0
doublereal Func1::isProportional(Func1& other)
{
    if (isIdentical(other)) {
        return 1.0;
    } else {
        return 0.0;
    }
}
Esempio n. 11
0
	void Process()
	{
		PathListIt it = paths.begin();
		while (it != paths.end()) {
			getFolderContent(*it);
			++it;
		}
		logInfo(L"Files to process:\t%8llu\n", data.size());

		logDebug(L"");
		std::sort(data.begin(), data.end(), CompareBySizeAndTime);
		std::pair<FilesListIt, FilesListIt> bounds;
		FilesListIt srch = data.begin();
		while (srch != data.end()) {
			logCounter(L"Files left:\t%8llu", std::distance(srch, data.end()));
			bounds = std::equal_range(srch, data.end(), *srch, CompareBySize);
			if (std::distance(bounds.first, bounds.second) == 1) {
				++Statistics::getInstance()->filesFoundUnique;
				data.erase(bounds.first);
			} else {
				while (srch != bounds.second) {
					FilesListIt it = srch;
					++it;
					shared_ptr<File>& f1 = *srch;
					while (it != bounds.second) {
						shared_ptr<File>& f2 = *it;
						AutoUTF buf1(f1->path());
						AutoUTF buf2(f2->path());
						{
							ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
							logDebug(L"Comparing files [size = %I64u]:\n", f1->size());
						}
						logDebug(L"  %s\n", buf1.c_str());
						logDebug(L"  %s\n", buf2.c_str());
						++Statistics::getInstance()->fileCompares;
						f1->refresh();
						f2->refresh();
						if (AttrMustMatch && f1->attr() != f2->attr()) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Attributes of files do not match, skipping\n");
							}
							Statistics::getInstance()->fileMetaDataMismatch++;
							++it;
							break;
						}
						if (TimeMustMatch && f1->mtime() != f2->mtime()) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Modification timestamps of files do not match, skipping\n");
							}
							Statistics::getInstance()->fileMetaDataMismatch++;
							++it;
							break;
						}
						if (!isSameVolume(*f1, *f2)) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Files ignored - on different volumes\n");
							}
							++Statistics::getInstance()->filesOnDifferentVolumes;
							++it;
							break;
						}
						if (f1 == f2) {
							++Statistics::getInstance()->fileAlreadyLinked;
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_GREEN);
								logDebug(L"  Files ignored - already linked\n");
							}
							++it;
							break;
						}
						if (f1->size() > FirstBlock) {
							if (!f1->LoadHashMini()) {
								break;
							}
							if (!f2->LoadHashMini()) {
								it = data.erase(it);
								continue;
							}
						} else {
							if (!f1->LoadHashFull()) {
								break;
							}
							if (!f2->LoadHashFull()) {
								it = data.erase(it);
								continue;
							}
						}
						if (isIdentical(*f1, *f2)) {
							++Statistics::getInstance()->fileContentSame;
							if (logLevel == LOG_VERBOSE) {
								{
									ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
									logVerbose(L"Comparing files [size = %I64u]:\n", f1->size());
								}
								logVerbose(L"  %s\n", buf1.c_str());
								logVerbose(L"  %s\n", buf2.c_str());
							}
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logVerbose(L"  Files are equal, hard link possible\n");
							}
							if (hardlink) {
								f1->hardlink(*f2);
							}
							Statistics::getInstance()->FreeSpaceIncrease += f1->size();
							it = data.erase(it);
						} else {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Files differ in content (hash)\n");
							}
							Statistics::getInstance()->hashComparesHit1++;
							++it;
						}
					}
					srch = data.erase(srch);
				}
			}
			srch = bounds.second;
		}
		logCounter(L"                              ");
	}
bool wasmint::HaltingProblemDetector::isLooping(InstructionCounter startCounter) {
    if (startCounter > vm_.instructionCounter()) {
        throw std::domain_error("startCounter is bigger than the current vm instruction counter");
    }

    bool result = false;
    const VMState backupState = vm_.state();

    totalStates_ = vm_.instructionCounter().toUint64();

    InstructionCounter lastCounter = vm_.instructionCounter();
    std::set<std::size_t> pagesThatNeedChecks;

    while (true) {
        const MachinePatch& lastPatch = vm_.history().getCheckpoint(lastCounter);

        if (lastPatch.influencedByExternalState()) {
            throw CantMakeHaltingDecision("Patch indicates that its related state depend on the external state");
        }

        InstructionCounter nextRollbackCounter = lastPatch.startCounter();

        if (nextRollbackCounter < startCounter)
            nextRollbackCounter = startCounter;

        vm_.simulateTo(nextRollbackCounter);

        for (auto iter = pagesThatNeedChecks.begin(); iter != pagesThatNeedChecks.end(); ) {
            std::size_t pageIndex = *iter;
            if (comparePage(vm_.heap(), backupState.heap(), pageIndex)) {
                iter = pagesThatNeedChecks.erase(iter);
            } else {
                ++iter;
            }
        }

        const std::set<std::size_t>& modifiedPages = lastPatch.heapPatch().modifiedChunks();

        bool modifiesRelevantPages = std::includes(modifiedPages.begin(), modifiedPages.end(),
                                                pagesThatNeedChecks.begin(), pagesThatNeedChecks.end());

        pagesThatNeedChecks.insert(modifiedPages.begin(), modifiedPages.end());

        if (modifiesRelevantPages) {
            InstructionCounter counter = nextRollbackCounter;
            while (counter != lastCounter) {
                if (isIdentical(vm_.state(), backupState, pagesThatNeedChecks)) {
                    ignoredStates_ += counter.toUint64();
                    result = true;
                    break;
                }
                ++counter;
                vm_.simulateTo(counter);
            }
        } else {
            ignoredStates_ += (lastCounter.toUint64() - nextRollbackCounter.toUint64());
        }
        if (!result) {
            lastCounter = nextRollbackCounter;
            if (lastCounter <= startCounter) {
                break;
            } else {
                --lastCounter;
            }
        } else {
            break;
        }
    }

    vm_.state() = backupState;
    assert(vm_.state() == backupState);

    return result;
}
Esempio n. 13
0
bool Shard::operator == (Shard &other)
{
    return isIdentical(&other);
}