コード例 #1
0
ファイル: table.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * table_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
table_t*
table_alloc (long numBucket, comparator_t* compare)
{
    table_t* tablePtr;
    long i;

    tablePtr = (table_t*)SEQ_MALLOC(sizeof(table_t));
    if (tablePtr == NULL) {
        return NULL;
    }

    tablePtr->buckets = (list_t**)SEQ_MALLOC(numBucket * sizeof(list_t*));
    if (tablePtr->buckets == NULL) {
        return NULL;
    }

    for (i = 0; i < numBucket; i++) {
        tablePtr->buckets[i] = list_alloc(compare);
        if (tablePtr->buckets[i] == NULL) {
            return NULL;
        }
    }

    tablePtr->numBucket = numBucket;

    return tablePtr;
}
コード例 #2
0
ファイル: net.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * net_alloc
 * =============================================================================
 */
net_t*
net_alloc (long numNode)
{
    net_t* netPtr;

    netPtr = (net_t*)SEQ_MALLOC(sizeof(net_t));
    if (netPtr) {
        vector_t* nodeVectorPtr = vector_alloc(numNode);
        if (nodeVectorPtr == NULL) {
            SEQ_FREE(netPtr);
            return NULL;
        }
        long i;
        for (i = 0; i < numNode; i++) {
            net_node_t* nodePtr = allocNode(i);
            if (nodePtr == NULL) {
                long j;
                for (j = 0; j < i; j++) {
                    nodePtr = (net_node_t*)vector_at(nodeVectorPtr, j);
                    freeNode(nodePtr);
                }
                vector_free(nodeVectorPtr);
                SEQ_FREE(netPtr);
                return NULL;
            }
            bool_t status = vector_pushBack(nodeVectorPtr, (void*)nodePtr);
            assert(status);
        }
        netPtr->nodeVectorPtr = nodeVectorPtr;
    }

    return netPtr;
}
コード例 #3
0
ファイル: heap.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * heap_insert
 * -- Returns false on failure
 * =============================================================================
 */
bool
heap_insert (heap_t* heapPtr, void* dataPtr)
{
    long size = heapPtr->size;
    long capacity = heapPtr->capacity;

    if ((size + 1) >= capacity) {
        long newCapacity = capacity * 2;
        void** newElements = (void**)SEQ_MALLOC(newCapacity * sizeof(void*));
        if (newElements == NULL) {
            return false;
        }
        heapPtr->capacity = newCapacity;
        long i;
        void** elements = heapPtr->elements;
        for (i = 0; i <= size; i++) {
            newElements[i] = elements[i];
        }
        SEQ_FREE(heapPtr->elements);
        heapPtr->elements = newElements;
    }

    size = ++(heapPtr->size);
    heapPtr->elements[size] = dataPtr;
    siftUp(heapPtr, size);

    return true;
}
コード例 #4
0
ファイル: client.c プロジェクト: riclas/rstm
/* =============================================================================
 * client_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
client_t*
client_alloc (long id,
              manager_t* managerPtr,
              long numOperation,
              long numQueryPerTransaction,
              long queryRange,
              long percentUser)
{
    client_t* clientPtr;

    clientPtr = (client_t*)SEQ_MALLOC(sizeof(client_t));
    if (clientPtr == NULL) {
        return NULL;
    }

    clientPtr->randomPtr = random_alloc();
    if (clientPtr->randomPtr == NULL) {
        return NULL;
    }

    clientPtr->id = id;
    clientPtr->managerPtr = managerPtr;
    random_seed(clientPtr->randomPtr, id);
    clientPtr->numOperation = numOperation;
    clientPtr->numQueryPerTransaction = numQueryPerTransaction;
    clientPtr->queryRange = queryRange;
    clientPtr->percentUser = percentUser;

    return clientPtr;
}
コード例 #5
0
ファイル: heap.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * heap_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
heap_t*
heap_alloc (long initCapacity, comparator_t* compare)
{
    heap_t* heapPtr;

    heapPtr = (heap_t*)SEQ_MALLOC(sizeof(heap_t));
    if (heapPtr) {
        long capacity = ((initCapacity > 0) ? (initCapacity) : (1));
        heapPtr->elements = (void**)SEQ_MALLOC(capacity * sizeof(void*));
        assert(heapPtr->elements);
        heapPtr->size = 0;
        heapPtr->capacity = capacity;
        heapPtr->compare = compare;
    }

    return heapPtr;
}
コード例 #6
0
ファイル: stream.c プロジェクト: hlitz/rstm_sitevm
/* =============================================================================
 * splitIntoPackets
 * -- Packets will be equal-size chunks except for last one, which will have
 *    all extra bytes
 * =============================================================================
 */
static void
splitIntoPackets (char* str,
                  long flowId,
                  random_t* randomPtr,
                  vector_t* allocVectorPtr,
                  queue_t* packetQueuePtr)
{
 
    long numByte = strlen(str);
    long numPacket = random_generate(randomPtr) % numByte + 1;

    long numDataByte = numByte / numPacket;

    long p;
    for (p = 0; p < (numPacket - 1); p++) {
        bool_t status;
        char* bytes = (char*)SEQ_MALLOC(PACKET_HEADER_LENGTH + numDataByte);
        assert(bytes);
        status = vector_pushBack(allocVectorPtr, (void*)bytes);
        assert(status);
        packet_t* packetPtr = (packet_t*)bytes;
        packetPtr->flowId      = flowId;
        packetPtr->fragmentId  = p;
        packetPtr->numFragment = numPacket;
        packetPtr->length      = numDataByte;
        memcpy(packetPtr->data, (str + p * numDataByte), numDataByte);
        status = queue_push(packetQueuePtr, (void*)packetPtr);
        assert(status);
    }

    bool_t status;
    long lastNumDataByte = numDataByte + numByte % numPacket;
    char* bytes = (char*)SEQ_MALLOC(PACKET_HEADER_LENGTH + lastNumDataByte);
    assert(bytes);
    status = vector_pushBack(allocVectorPtr, (void*)bytes);
    assert(status);
    packet_t* packetPtr = (packet_t*)bytes;
    packetPtr->flowId      = flowId;
    packetPtr->fragmentId  = p;
    packetPtr->numFragment = numPacket;
    packetPtr->length      = lastNumDataByte;
    memcpy(packetPtr->data, (str + p * numDataByte), lastNumDataByte);
    status = queue_push(packetQueuePtr, (void*)packetPtr);
    assert(status);
}
コード例 #7
0
ファイル: rbtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * rbtree_alloc
 * =============================================================================
 */
rbtree_t*
rbtree_alloc (comparator_t* compare)
{
    rbtree_t* n = (rbtree_t* )SEQ_MALLOC(sizeof(*n));
    if (n) {
        n->compare = ((compare != NULL) ? compare : &rbtree_comparekeysdefault);
        n->root = NULL;
    }
    return n;
}
コード例 #8
0
ファイル: random.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * random_alloc
 * -- Returns NULL if failure
 * =============================================================================
 */
random_t*
random_alloc (void)
{
    random_t* randomPtr = (random_t*)SEQ_MALLOC(sizeof(random_t));
    if (randomPtr != NULL) {
        randomPtr->mti = N;
        init_genrand(randomPtr->mt, &(randomPtr->mti), RANDOM_DEFAULT_SEED);
    }

    return randomPtr;
}
コード例 #9
0
ファイル: data.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * data_alloc
 * =============================================================================
 */
data_t*
data_alloc (long numVar, long numRecord, random_t* randomPtr)
{
    data_t* dataPtr;

    dataPtr = (data_t*)SEQ_MALLOC(sizeof(data_t));
    if (dataPtr) {
        long numDatum = numVar * numRecord;
        dataPtr->records = (char*)SEQ_MALLOC(numDatum * sizeof(char));
        if (dataPtr->records == NULL) {
            SEQ_FREE(dataPtr);
            return NULL;
        }
        memset(dataPtr->records, DATA_INIT, (numDatum * sizeof(char)));
        dataPtr->numVar = numVar;
        dataPtr->numRecord = numRecord;
        dataPtr->randomPtr = randomPtr;
    }

    return dataPtr;
}
コード例 #10
0
ファイル: grid.c プロジェクト: nmldiegues/stamp-rtm
/* =============================================================================
 * grid_alloc
 * =============================================================================
 */
grid_t*
grid_alloc (long width, long height, long depth)
{
    grid_t* gridPtr;

    gridPtr = (grid_t*)SEQ_MALLOC(sizeof(grid_t));
    if (gridPtr) {
        gridPtr->width  = width;
        gridPtr->height = height;
        gridPtr->depth  = depth;
        long n = width * height * depth;
        long* points_unaligned = (long*)SEQ_MALLOC(n * sizeof(long) + CACHE_LINE_SIZE);
        assert(points_unaligned);
        gridPtr->points_unaligned = points_unaligned;
        gridPtr->points = (long*)((char*)(((unsigned long)points_unaligned
                                          & ~(CACHE_LINE_SIZE-1)))
                                  + CACHE_LINE_SIZE);
        memset(gridPtr->points, GRID_POINT_EMPTY, (n * sizeof(long)));
    }

    return gridPtr;
}
コード例 #11
0
ファイル: list.c プロジェクト: riclas/rstm
/* =============================================================================
 * allocNode
 * -- Returns NULL on failure
 * =============================================================================
 */
static list_node_t*
allocNode (void* dataPtr)
{
    list_node_t* nodePtr = (list_node_t*)SEQ_MALLOC(sizeof(list_node_t));
    if (nodePtr == NULL) {
        return NULL;
    }

    nodePtr->dataPtr = dataPtr;
    nodePtr->nextPtr = NULL;

    return nodePtr;
}
コード例 #12
0
ファイル: adtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * adtree_alloc
 * =============================================================================
 */
adtree_t*
adtree_alloc ()
{
    adtree_t* adtreePtr;

    adtreePtr = (adtree_t*)SEQ_MALLOC(sizeof(adtree_t));
    if (adtreePtr) {
        adtreePtr->numVar = -1L;
        adtreePtr->numRecord = -1L;
        adtreePtr->rootNodePtr = NULL;
    }

    return adtreePtr;
}
コード例 #13
0
ファイル: coordinate.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * coordinate_alloc
 * =============================================================================
 */
coordinate_t*
coordinate_alloc (long x, long y, long z)
{
    coordinate_t* coordinatePtr;

    coordinatePtr = (coordinate_t*)SEQ_MALLOC(sizeof(coordinate_t));
    if (coordinatePtr) {
        coordinatePtr->x = x;
        coordinatePtr->y = y;
        coordinatePtr->z = z;
    }

    return coordinatePtr;
}
コード例 #14
0
ファイル: decoder.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * decoder_alloc
 * =============================================================================
 */
decoder_t*
decoder_alloc ()
{
    decoder_t* decoderPtr;

    decoderPtr = (decoder_t*)SEQ_MALLOC(sizeof(decoder_t));
    if (decoderPtr) {
        decoderPtr->fragmentedMapPtr = MAP_ALLOC(NULL, NULL);
        assert(decoderPtr->fragmentedMapPtr);
        decoderPtr->decodedQueuePtr = queue_alloc(1024);
        assert(decoderPtr->decodedQueuePtr);
    }

    return decoderPtr;
}
コード例 #15
0
ファイル: router.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * router_alloc
 * =============================================================================
 */
router_t*
router_alloc (long xCost, long yCost, long zCost, long bendCost)
{
  router_t* routerPtr;

  routerPtr = (router_t*)SEQ_MALLOC(sizeof(router_t));
  if (routerPtr) {
    routerPtr->xCost = xCost;
    routerPtr->yCost = yCost;
    routerPtr->zCost = zCost;
    routerPtr->bendCost = bendCost;
  }

  return routerPtr;
}
コード例 #16
0
ファイル: segments.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * segments_alloc
 * -- Does almost all the memory allocation for random segments
 * -- The actual number of segments created by 'segments_create' may be larger
 *    than 'minNum' to ensure the segments overlap and cover the entire gene
 * -- Returns NULL on failure
 * =============================================================================
 */
segments_t*
segments_alloc (long length, long minNum)
{
    segments_t* segmentsPtr;
    long i;
    char* string;

    segmentsPtr = (segments_t*)SEQ_MALLOC(sizeof(segments_t));
    if (segmentsPtr == NULL) {
        return NULL;
    }

    /* Preallocate for the min number of segments we will need */
    segmentsPtr->strings = (char**)SEQ_MALLOC(minNum * sizeof(char*));
    if (segmentsPtr->strings == NULL) {
        return NULL;
    }

    string = (char*)SEQ_MALLOC(minNum * (length+1) * sizeof(char));
    if (string == NULL) {
        return NULL;
    }
    for (i = 0; i < minNum; i++) {
        segmentsPtr->strings[i] = &string[i * (length+1)];
        segmentsPtr->strings[i][length] = '\0';
    }
    segmentsPtr->minNum = minNum;
    segmentsPtr->length = length;

    segmentsPtr->contentsPtr = vector_alloc(minNum);
    if (segmentsPtr->contentsPtr == NULL) {
        return NULL;
    }

    return segmentsPtr;
}
コード例 #17
0
ファイル: adtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * allocVary
 * =============================================================================
 */
adtree_vary_t*
allocVary (long index)
{
    adtree_vary_t* varyPtr;

    varyPtr = (adtree_vary_t*)SEQ_MALLOC(sizeof(adtree_vary_t));
    if (varyPtr) {
        varyPtr->index = index;
        varyPtr->mostCommonValue = -1;
        varyPtr->zeroNodePtr = NULL;
        varyPtr->oneNodePtr = NULL;
    }

    return varyPtr;
}
コード例 #18
0
ファイル: customer.c プロジェクト: amohtasham/rstm
customer_t*
customer_alloc_seq (long id)
{
    customer_t* customerPtr;

    customerPtr = (customer_t*)SEQ_MALLOC(sizeof(customer_t));
    assert(customerPtr != NULL);

    customerPtr->id = id;

    customerPtr->reservationInfoListPtr = Plist_alloc(&customer_comparereservationinfo);
    assert(customerPtr->reservationInfoListPtr != NULL);

    return customerPtr;
}
コード例 #19
0
ファイル: manager.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * manager_alloc
 * =============================================================================
 */
manager_t*
manager_alloc ()
{
    manager_t* managerPtr;

    managerPtr = (manager_t*)SEQ_MALLOC(sizeof(manager_t));
    assert(managerPtr != NULL);

    managerPtr->carTablePtr = tableAlloc();
    managerPtr->roomTablePtr = tableAlloc();
    managerPtr->flightTablePtr = tableAlloc();
    managerPtr->customerTablePtr = tableAlloc();
    assert(managerPtr->carTablePtr != NULL);
    assert(managerPtr->roomTablePtr != NULL);
    assert(managerPtr->flightTablePtr != NULL);
    assert(managerPtr->customerTablePtr != NULL);

    return managerPtr;
}
コード例 #20
0
ファイル: adtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * allocNode
 * =============================================================================
 */
adtree_node_t*
allocNode (long index)
{
    adtree_node_t* nodePtr;

    nodePtr = (adtree_node_t*)SEQ_MALLOC(sizeof(adtree_node_t));
    if (nodePtr) {
        nodePtr->varyVectorPtr = vector_alloc(1);
        if (nodePtr->varyVectorPtr == NULL) {
            SEQ_FREE(nodePtr);
            return NULL;
        }
        nodePtr->index = index;
        nodePtr->value = -1;
        nodePtr->count = -1;
    }

    return nodePtr;
}
コード例 #21
0
ファイル: decoder.c プロジェクト: hlitz/rstm_sitevm_dune
/* =============================================================================
 * decoder_alloc
 * =============================================================================
 */
decoder_t*
decoder_alloc (long numFlow)
{
    decoder_t* decoderPtr;

    decoderPtr = (decoder_t*)SEQ_MALLOC(sizeof(decoder_t));
    if (decoderPtr) {
      printf("hastable alloc size %lx\n", numFlow);
#ifdef MAP_USE_RBTREE
      decoderPtr->fragmentedMapPtr = MAP_ALLOC(NULL, NULL);
#else
      decoderPtr->fragmentedMapPtr = hashtable_alloc(numFlow, NULL, NULL, 2, 2);
#endif
      assert(decoderPtr->fragmentedMapPtr);
        decoderPtr->decodedQueuePtr = queue_alloc(1024);
        assert(decoderPtr->decodedQueuePtr);
    }

    return decoderPtr;
}
コード例 #22
0
ファイル: sequencer.c プロジェクト: jaingaurav/rstm
static segments_t*
createSegments (char* segments[])
{
    long i = 0;
    segments_t* segmentsPtr = (segments_t*)SEQ_MALLOC(sizeof(segments));

    segmentsPtr->length = strlen(segments[0]);
    segmentsPtr->contentsPtr = vector_alloc(1);

    while (segments[i] != NULL) {
        bool status = vector_pushBack(segmentsPtr->contentsPtr,
                                      (void*)segments[i]);
        assert(status);
        i++;
    }

    segmentsPtr->minNum = vector_getSize(segmentsPtr->contentsPtr);

    return segmentsPtr;
}
コード例 #23
0
ファイル: stream.c プロジェクト: hlitz/rstm_sitevm
/* =============================================================================
 * stream_alloc
 * =============================================================================
 */
stream_t*
stream_alloc (long percentAttack)
{
    stream_t* streamPtr;

    streamPtr = (stream_t*)SEQ_MALLOC(sizeof(stream_t));
    if (streamPtr) {
        assert(percentAttack >= 0 && percentAttack <= 100);
        streamPtr->percentAttack = percentAttack;
        streamPtr->randomPtr = random_alloc();
        assert(streamPtr->randomPtr);
        streamPtr->allocVectorPtr = vector_alloc(1);
        assert(streamPtr->allocVectorPtr);
        streamPtr->packetQueuePtr = queue_alloc(-1);
        assert(streamPtr->packetQueuePtr);
        streamPtr->attackMapPtr = MAP_ALLOC(NULL, NULL);
        assert(streamPtr->attackMapPtr);
    }

    return streamPtr;
}
コード例 #24
0
ファイル: hashtable.c プロジェクト: hlitz/rstm_sitevm_dune
hashtable_t*
hashtable_alloc (long initNumBucket,
                 ulong_t (*hash)(const void*),
                 comparator_t* comparePairs,
                 long resizeRatio,
                 long growthFactor)
{
  if(comparePairs==NULL){
    comparePairs = &default_hashtable_comparator;
  }    
    hashtable_t* hashtablePtr;
    resizeRatio = -1;
    growthFactor = -1;
    hashtablePtr = (hashtable_t*)SEQ_MALLOC(sizeof(hashtable_t));
    if (hashtablePtr == NULL) {
        return NULL;
    }
    if(hash==NULL){
      hash = &func_hash;
    }

    hashtablePtr->buckets = allocBuckets(initNumBucket, comparePairs);
    if (hashtablePtr->buckets == NULL) {
        SEQ_FREE(hashtablePtr);
        return NULL;
    }

    hashtablePtr->numBucket = initNumBucket;
#ifdef HASHTABLE_SIZE_FIELD
    hashtablePtr->size = 0;
#endif
    hashtablePtr->hash = hash;
    hashtablePtr->comparePairs = comparePairs;
    hashtablePtr->resizeRatio = ((resizeRatio < 0) ?
                                  HASHTABLE_DEFAULT_RESIZE_RATIO : resizeRatio);
    hashtablePtr->growthFactor = ((growthFactor < 0) ?
                                  HASHTABLE_DEFAULT_GROWTH_FACTOR : growthFactor);

    return hashtablePtr;
}
コード例 #25
0
ファイル: net.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * allocNode
 * =============================================================================
 */
static net_node_t*
allocNode (long id)
{
    net_node_t* nodePtr;

    nodePtr = (net_node_t*)SEQ_MALLOC(sizeof(net_node_t));
    if (nodePtr) {
        nodePtr->parentIdListPtr = Plist_alloc(&net_compareid);
        if (nodePtr->parentIdListPtr == NULL) {
            SEQ_FREE(nodePtr);
            return NULL;
        }
        nodePtr->childIdListPtr = Plist_alloc(&net_compareid);
        if (nodePtr->childIdListPtr == NULL) {
            list_free(nodePtr->parentIdListPtr);
            SEQ_FREE(nodePtr);
            return NULL;
        }
        nodePtr->id = id;
    }

    return nodePtr;
}
コード例 #26
0
ファイル: element.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * element_alloc
 *
 * Contains a copy of input arg 'coordinates'
 * =============================================================================
 */
element_t*
element_alloc (coordinate_t* coordinates, long numCoordinate)
{
    element_t* elementPtr;

    elementPtr = (element_t*)SEQ_MALLOC(sizeof(element_t));
    if (elementPtr) {
        long i;
        for (i = 0; i < numCoordinate; i++) {
            elementPtr->coordinates[i] = coordinates[i];
        }
        elementPtr->numCoordinate = numCoordinate;
        minimizeCoordinates(elementPtr);
        checkAngles(elementPtr);
        calculateCircumCircle(elementPtr);
        initEdges(elementPtr, coordinates, numCoordinate);
        elementPtr->neighborListPtr = Plist_alloc(&element_listcompare);
        assert(elementPtr->neighborListPtr);
        elementPtr->isGarbage = false;
        elementPtr->isReferenced = false;
    }

    return elementPtr;
}
コード例 #27
0
ファイル: data.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * data_generate
 * -- Binary variables of random PDFs
 * -- If seed is <0, do not reseed
 * -- Returns random network
 * =============================================================================
 */
net_t*
data_generate (data_t* dataPtr, long seed, long maxNumParent, long percentParent)
{
    random_t* randomPtr = dataPtr->randomPtr;
    if (seed >= 0) {
        random_seed(randomPtr, seed);
    }

    /*
     * Generate random Bayesian network
     */

    long numVar = dataPtr->numVar;
    net_t* netPtr = net_alloc(numVar);
    assert(netPtr);
    net_generateRandomEdges(netPtr, maxNumParent, percentParent, randomPtr);

    /*
     * Create a threshold for each of the possible permutation of variable
     * value instances
     */

    long** thresholdsTable = (long**)SEQ_MALLOC(numVar * sizeof(long*));
    assert(thresholdsTable);
    long v;
    for (v = 0; v < numVar; v++) {
        list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, v);
        long numThreshold = 1 << list_getSize(parentIdListPtr);
        long* thresholds = (long*)SEQ_MALLOC(numThreshold * sizeof(long));
        assert(thresholds);
        long t;
        for (t = 0; t < numThreshold; t++) {
            long threshold = random_generate(randomPtr) % (DATA_PRECISION + 1);
            thresholds[t] = threshold;
        }
        thresholdsTable[v] = thresholds;
    }

    /*
     * Create variable dependency ordering for record generation
     */

    long* order = (long*)SEQ_MALLOC(numVar * sizeof(long));
    assert(order);
    long numOrder = 0;

    queue_t* workQueuePtr = queue_alloc(-1);
    assert(workQueuePtr);

    vector_t* dependencyVectorPtr = vector_alloc(1);
    assert(dependencyVectorPtr);

    bitmap_t* orderedBitmapPtr = bitmap_alloc(numVar);
    assert(orderedBitmapPtr);
    bitmap_clearAll(orderedBitmapPtr);

    bitmap_t* doneBitmapPtr = bitmap_alloc(numVar);
    assert(doneBitmapPtr);
    bitmap_clearAll(doneBitmapPtr);
    v = -1;
    while ((v = bitmap_findClear(doneBitmapPtr, (v + 1))) >= 0) {
        list_t* childIdListPtr = net_getChildIdListPtr(netPtr, v);
        long numChild = list_getSize(childIdListPtr);
        if (numChild == 0) {

            bool status;

            /*
             * Use breadth-first search to find net connected to this leaf
             */

            queue_clear(workQueuePtr);
            status = queue_push(workQueuePtr, (void*)v);
            assert(status);
            while (!queue_isEmpty(workQueuePtr)) {
                long id = (long)queue_pop(workQueuePtr);
                status = bitmap_set(doneBitmapPtr, id);
                assert(status);
                status = vector_pushBack(dependencyVectorPtr, (void*)id);
                assert(status);
                list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, id);
                list_iter_t it;
                list_iter_reset(&it, parentIdListPtr);
                while (list_iter_hasNext(&it, parentIdListPtr)) {
                    long parentId = (long)list_iter_next(&it, parentIdListPtr);
                    status = queue_push(workQueuePtr, (void*)parentId);
                    assert(status);
                }
            }

            /*
             * Create ordering
             */

            long i;
            long n = vector_getSize(dependencyVectorPtr);
            for (i = 0; i < n; i++) {
                long id = (long)vector_popBack(dependencyVectorPtr);
                if (!bitmap_isSet(orderedBitmapPtr, id)) {
                    bitmap_set(orderedBitmapPtr, id);
                    order[numOrder++] = id;
                }
            }

        }
    }
    assert(numOrder == numVar);

    /*
     * Create records
     */

    char* record = dataPtr->records;
    long r;
    long numRecord = dataPtr->numRecord;
    for (r = 0; r < numRecord; r++) {
        long o;
        for (o = 0; o < numOrder; o++) {
            long v = order[o];
            list_t* parentIdListPtr = net_getParentIdListPtr(netPtr, v);
            long index = 0;
            list_iter_t it;
            list_iter_reset(&it, parentIdListPtr);
            while (list_iter_hasNext(&it, parentIdListPtr)) {
                long parentId = (long)list_iter_next(&it, parentIdListPtr);
                long value = record[parentId];
                assert(value != DATA_INIT);
                index = (index << 1) + value;
            }
            long rnd = random_generate(randomPtr) % DATA_PRECISION;
            long threshold = thresholdsTable[v][index];
            record[v] = ((rnd < threshold) ? 1 : 0);
        }
        record += numVar;
        assert(record <= (dataPtr->records + numRecord * numVar));
    }

    /*
     * Clean up
     */

    bitmap_free(doneBitmapPtr);
    bitmap_free(orderedBitmapPtr);
    vector_free(dependencyVectorPtr);
    queue_free(workQueuePtr);
    SEQ_FREE(order);
    for (v = 0; v < numVar; v++) {
        SEQ_FREE(thresholdsTable[v]);
    }
    SEQ_FREE(thresholdsTable);

    return netPtr;
}
コード例 #28
0
ファイル: rbtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * getNode
 * =============================================================================
 */
static node_t*
getNode ()
{
    node_t* n = (node_t*)SEQ_MALLOC(sizeof(*n));
    return n;
}
コード例 #29
0
ファイル: sequencer.c プロジェクト: jaingaurav/rstm
/* =============================================================================
 * sequencer_alloc
 * -- Returns NULL on failure
 * =============================================================================
 */
sequencer_t*
sequencer_alloc (long geneLength, long segmentLength, segments_t* segmentsPtr)
{
    sequencer_t* sequencerPtr;
    long maxNumUniqueSegment = geneLength - segmentLength + 1;
    long i;

    sequencerPtr = (sequencer_t*)SEQ_MALLOC(sizeof(sequencer_t));
    if (sequencerPtr == NULL) {
        return NULL;
    }

    sequencerPtr->uniqueSegmentsPtr =
        hashtable_alloc(geneLength, &hashSegment, &sequencer_comparesegment, -1, -1);
    if (sequencerPtr->uniqueSegmentsPtr == NULL) {
        return NULL;
    }

    /* For finding a matching entry */
    sequencerPtr->endInfoEntries =
        (endInfoEntry_t*)SEQ_MALLOC(maxNumUniqueSegment * sizeof(endInfoEntry_t));
    for (i = 0; i < maxNumUniqueSegment; i++) {
        endInfoEntry_t* endInfoEntryPtr = &sequencerPtr->endInfoEntries[i];
        endInfoEntryPtr->isEnd = true;
        endInfoEntryPtr->jumpToNext = 1;
    }
    sequencerPtr->startHashToConstructEntryTables =
        (table_t**)SEQ_MALLOC(segmentLength * sizeof(table_t*));
    if (sequencerPtr->startHashToConstructEntryTables == NULL) {
        return NULL;
    }
    for (i = 1; i < segmentLength; i++) { /* 0 is dummy entry */
        sequencerPtr->startHashToConstructEntryTables[i] =
            table_alloc(geneLength, NULL);
        if (sequencerPtr->startHashToConstructEntryTables[i] == NULL) {
            return NULL;
        }
    }
    sequencerPtr->segmentLength = segmentLength;

    /* For constructing sequence */
    sequencerPtr->constructEntries =
        (constructEntry_t*)SEQ_MALLOC(maxNumUniqueSegment * sizeof(constructEntry_t));
    if (sequencerPtr->constructEntries == NULL) {
        return NULL;
    }
    for (i= 0; i < maxNumUniqueSegment; i++) {
        constructEntry_t* constructEntryPtr = &sequencerPtr->constructEntries[i];
        constructEntryPtr->isStart = true;
        constructEntryPtr->segment = NULL;
        constructEntryPtr->endHash = 0;
        constructEntryPtr->startPtr = constructEntryPtr;
        constructEntryPtr->nextPtr = NULL;
        constructEntryPtr->endPtr = constructEntryPtr;
        constructEntryPtr->overlap = 0;
        constructEntryPtr->length = segmentLength;
    }
    sequencerPtr->hashToConstructEntryTable = table_alloc(geneLength, NULL);
    if (sequencerPtr->hashToConstructEntryTable == NULL) {
        return NULL;
    }

    sequencerPtr->segmentsPtr = segmentsPtr;

    return sequencerPtr;
}
コード例 #30
0
ファイル: decoder.c プロジェクト: hlitz/rstm_sitevm_dune
int
main ()
{
    decoder_t* decoderPtr;

    puts("Starting...");

    decoderPtr = decoder_alloc();
    assert(decoderPtr);

    long numDataByte = 3;
    long numPacketByte = PACKET_HEADER_LENGTH + numDataByte;

    char* abcBytes = (char*)SEQ_MALLOC(numPacketByte);
    assert(abcBytes);
    packet_t* abcPacketPtr;
    abcPacketPtr = (packet_t*)abcBytes;
    abcPacketPtr->flowId = 1;
    abcPacketPtr->fragmentId = 0;
    abcPacketPtr->numFragment = 2;
    abcPacketPtr->length = numDataByte;
    abcPacketPtr->data[0] = 'a';
    abcPacketPtr->data[1] = 'b';
    abcPacketPtr->data[2] = 'c';

    char* defBytes = (char*)SEQ_MALLOC(numPacketByte);
    assert(defBytes);
    packet_t* defPacketPtr;
    defPacketPtr = (packet_t*)defBytes;
    defPacketPtr->flowId = 1;
    defPacketPtr->fragmentId = 1;
    defPacketPtr->numFragment = 2;
    defPacketPtr->length = numDataByte;
    defPacketPtr->data[0] = 'd';
    defPacketPtr->data[1] = 'e';
    defPacketPtr->data[2] = 'f';

    assert(decoder_process(decoderPtr, abcBytes, numDataByte) == ERROR_SHORT);

    abcPacketPtr->flowId = -1;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_FLOWID);
    abcPacketPtr->flowId = 1;

    abcPacketPtr->fragmentId = -1;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_FRAGMENTID);
    abcPacketPtr->fragmentId = 0;

    abcPacketPtr->fragmentId = 2;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_FRAGMENTID);
    abcPacketPtr->fragmentId = 0;

    abcPacketPtr->fragmentId = 2;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_FRAGMENTID);
    abcPacketPtr->fragmentId = 0;

    abcPacketPtr->length = -1;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_LENGTH);
    abcPacketPtr->length = numDataByte;

    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_NONE);
    defPacketPtr->numFragment = 3;
    assert(decoder_process(decoderPtr, defBytes, numPacketByte) == ERROR_NUMFRAGMENT);
    defPacketPtr->numFragment = 2;

    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_NONE);
    defPacketPtr->fragmentId = 0;
    assert(decoder_process(decoderPtr, defBytes, numPacketByte) == ERROR_INCOMPLETE);
    defPacketPtr->fragmentId = 1;

    long flowId;
    assert(decoder_process(decoderPtr, defBytes, numPacketByte) == ERROR_NONE);
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_NONE);
    char* str = decoder_getComplete(decoderPtr, &flowId);
    assert(strcmp(str, "abcdef") == 0);
    SEQ_FREE(str);
    assert(flowId == 1);

    abcPacketPtr->numFragment = 1;
    assert(decoder_process(decoderPtr, abcBytes, numPacketByte) == ERROR_NONE);
    str = decoder_getComplete(decoderPtr, &flowId);
    assert(strcmp(str, "abc") == 0);
    SEQ_FREE(str);
    abcPacketPtr->numFragment = 2;
    assert(flowId == 1);

    str = decoder_getComplete(decoderPtr, &flowId);
    assert(str == NULL);
    assert(flowId == -1);

    decoder_free(decoderPtr);

    SEQ_FREE(abcBytes);
    SEQ_FREE(defBytes);

    puts("All tests passed.");

    return 0;
}