bool
ccnxManifestHashGroup_Equals(const CCNxManifestHashGroup *objectA, const CCNxManifestHashGroup *objectB)
{
    if (objectA == objectB) {
        return true;
    }
    if (objectA == NULL || objectB == NULL) {
        return false;
    }

    if (objectA->dataSize == objectB->dataSize) {
        if (objectA->entrySize == objectB->entrySize) {
            if (objectA->blockSize == objectB->blockSize) {
                if (objectA->treeHeight == objectB->treeHeight) {
                    if (ccnxName_Equals(objectA->locator, objectB->locator)) {
                        if (parcBuffer_Equals(objectA->overallDataDigest, objectB->overallDataDigest)) {
                            if (parcLinkedList_Size(objectA->pointers) == parcLinkedList_Size(objectB->pointers)) {
                                for (size_t i = 0; i < parcLinkedList_Size(objectA->pointers); i++) {
                                    CCNxManifestHashGroupPointer *ptrA = parcLinkedList_GetAtIndex(objectA->pointers, i);
                                    CCNxManifestHashGroupPointer *ptrB = parcLinkedList_GetAtIndex(objectB->pointers, i);
                                    if (!_CCNxManifestHashGroupPointer_Equals(ptrA, ptrB)) {
                                        return false;
                                    }
                                }
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }

    return false;
}
Ejemplo n.º 2
0
static size_t
_parcSortedList_GetInsertionIndex(const PARCSortedList *instance, const PARCObject *element)
{
    ssize_t low = 0;
    ssize_t high = parcLinkedList_Size(instance->list) - 1;

    if (high == -1) {
        return 0;
    }

    while (true) {
        ssize_t midpoint = (low + (high - low) / 2);
        PARCObject *e = parcLinkedList_GetAtIndex(instance->list, midpoint);
        int signum = instance->compare(element, e);
        if (high == low) {
            if (signum < 0) {
                return high;
            } else if (signum > 0) {
                return low + 1;
            } else {
                return low;
            }
        }

        if (signum < 0) {
            high = midpoint;
        } else if (signum > 0) {
            low = midpoint + 1;
        } else {
            return midpoint;
        }
    }

    return -1;
}
Ejemplo n.º 3
0
double
parcHashMap_GetClusteringNumber(const PARCHashMap *hashMap)
{
    // This function compute the standard deviation of the chain-lengths
    // from a value of 1.0 (as opposed to the mean) and weights the
    // result by in inverse of the current load factor. The deviation
    // from 1.0 is used because the hashmap's max load factor is < 1.0 and
    // thus the ideal average chain-length is 1.0
    //
    // A result of 0.0 equates to an ideal distribution, a result of ~1.0 should
    // represent a fairly normal or random distribution, and a result > 1.5 or so
    // implies some amount of undesirable clumping may be happening.

    size_t totalLength = 0;
    double variance = 0;

    // Compute the variance vs 1.0
    for (size_t i = 0; i < hashMap->capacity; ++i) {
        if (hashMap->buckets[i] != NULL) {
            size_t bucketSize = parcLinkedList_Size(hashMap->buckets[i]);
            totalLength += bucketSize;
            variance += (bucketSize - 1) * (bucketSize - 1); //Variance relative to 1
        }
    }
    variance /= ((double)totalLength);

    // Compute the standard deviation
    double standardDeviation = sqrt(variance);

    // Weight the standard deviation by the inverse of the current load factor
    return standardDeviation * ((double)hashMap->capacity/(double)totalLength);
}
PARCJSON *
ccnxManifestHashGroup_ToJson(const CCNxManifestHashGroup *group)
{
    PARCJSON *root = parcJSON_Create();

    PARCJSONArray *ptrList = parcJSONArray_Create();
    for (size_t i = 0; i < parcLinkedList_Size(group->pointers); i++) {
        CCNxManifestHashGroupPointer *ptr = (CCNxManifestHashGroupPointer *) parcLinkedList_GetAtIndex(group->pointers, i);
        PARCJSON *ptrJson = parcJSON_Create();

        // Type.
        parcJSON_AddInteger(ptrJson, "type", ccnxManifestHashGroupPointer_GetType(ptr));

        // Digest.
        char *digestString = parcBuffer_ToHexString(ptr->digest);
        parcJSON_AddString(ptrJson, "digest", digestString);
        parcMemory_Deallocate(&digestString);

        // Add the tuple to the list.
        PARCJSONValue *val = parcJSONValue_CreateFromJSON(ptrJson);
        parcJSONArray_AddValue(ptrList, val);

        // Cleanup
        parcJSONValue_Release(&val);
        parcJSON_Release(&ptrJson);
    }
    root = parcJSON_AddArray(root, "HashGroup", ptrList);
    parcJSONArray_Release(&ptrList);

    if (group->overallDataDigest != NULL) {
        char *digestString = parcBuffer_ToHexString(group->overallDataDigest);
        root = parcJSON_AddString(root, "overallDataDigest", digestString);
        parcMemory_Deallocate((void **) &digestString);
    }

    if (group->locator != NULL) {
        char *locatorString = ccnxName_ToString(group->locator);
        root = parcJSON_AddString(root, "locator", locatorString);
        parcMemory_Deallocate((void **) &locatorString);
    }

    if (group->entrySize > 0) {
        root = parcJSON_AddInteger(root, "entrySize", group->entrySize);
    }

    if (group->dataSize > 0) {
        root = parcJSON_AddInteger(root, "dataSize", group->dataSize);
    }

    if (group->blockSize > 0) {
        root = parcJSON_AddInteger(root, "blockSize", group->blockSize);
    }

    if (group->treeHeight > 0) {
        root = parcJSON_AddInteger(root, "treeHeight", group->treeHeight);
    }

    return root;
}
Ejemplo n.º 5
0
void
parcSortedList_Add(PARCSortedList *instance, PARCObject *element)
{
    size_t insertionPoint = _parcSortedList_GetInsertionIndex(instance, element);
    assertTrue(insertionPoint >= 0 && insertionPoint <= parcLinkedList_Size(instance->list),
               "%zd is bad insertion point.  Must be >=0 and <= %zd", insertionPoint, parcLinkedList_Size(instance->list));

    parcLinkedList_InsertAtIndex(instance->list, insertionPoint, element);
}
static void *
_ccnxManifestHashGroupIterator_Next(CCNxManifestHashGroup *group, void *state)
{
    _HashgroupIteratorState *thestate = (_HashgroupIteratorState *) state;
    thestate->pointerNumber++;

    if (thestate->pointerNumber == parcLinkedList_Size(group->pointers)) {
        thestate->atEnd = true;
    }

    return thestate;
}
bool
ccnxManifestHashGroup_IsFull(const CCNxManifestHashGroup *group)
{
    size_t size = parcLinkedList_Size(group->pointers);
    return size >= MAX_NUMBER_OF_POINTERS;
}
size_t
ccnxManifestHashGroup_GetNumberOfPointers(const CCNxManifestHashGroup *group)
{
    return parcLinkedList_Size(group->pointers);
}
Ejemplo n.º 9
0
PARCObject *
parcSortedList_GetLast(const PARCSortedList *list)
{
    return parcLinkedList_GetAtIndex(list->list, parcLinkedList_Size(list->list) - 1);
}
Ejemplo n.º 10
0
size_t
parcSortedList_Size(const PARCSortedList *list)
{
    return parcLinkedList_Size(list->list);
}