Esempio n. 1
0
int fdset_poll2(fdset *fds) {
    int r, i;
    while (1) {
        FD_ZERO(&fds->rfds);
        FD_ZERO(&fds->exfds);
        FD_ZERO(&fds->wfds);
        fds->max_fd = -1;

        if (vector_empty(&fds->rev) && vector_empty(&fds->exev)) {
            // We have nothing left to select(2) on.
            return 0;
        }

        fdset_populate(fds, &fds->rfds, &fds->rev);
        fdset_populate(fds, &fds->exfds, &fds->exev);

        r = select(fds->max_fd+1, &fds->rfds, 0, &fds->exfds, &fds->timeout);
        if (r < 0) {
            if (errno != EINTR) {
                perror("select");
                return r;
            }
            continue;
        }
        if (r == 0) {
            // Timeout case
            fds->timeout_cb(NULL);
            continue;
        }
        for (i = 0; i < vector_size(&fds->rev); ++i) {
            select_event_t *pse = (select_event_t*)vector_at(&fds->rev, i);
            if (FD_ISSET(pse->fd, &fds->rfds)) {
                VERBOSE("FD %d is read ready\n", pse->fd);
                pse->callback(pse->opaque);
            }
        }
        for (i = 0; i < vector_size(&fds->exev); ++i) {
            int rev_pos;
            select_event_t se;
            se = *(select_event_t*)vector_at(&fds->exev, i);
            if (FD_ISSET(se.fd, &fds->exfds)) {
                INFO("FD %d is in ERROR\n", se.fd);
                // Also remove this fd from the list of ex/read events
                // to monitor.
                vector_erase(&fds->exev, i);
                --i;
                // Remove from read events list as well.
                rev_pos = algorithm_find(&fds->rev, &se.fd, find_by_fd);
                if (rev_pos != -1) {
                    vector_erase(&fds->rev, rev_pos);
                }
                se.callback(se.opaque);

            } // if ()

        } // for ()

    } // while (1)

} // fdset_poll2()
Esempio n. 2
0
/**
 * Erases all the elements of an hashtable.
 */
void _hashtable_clear(_hashtable_t* pt_hashtable)
{
    size_t       t_bucketcount = 0;
    size_t       i = 0;
    _hashnode_t* pt_node = NULL;
    _hashnode_t* pt_deletion = NULL;
    bool_t       b_result = false;

    assert(pt_hashtable != NULL);
    assert(_hashtable_is_inited(pt_hashtable) || _hashtable_is_created(pt_hashtable));

    t_bucketcount = vector_size(&pt_hashtable->_vec_bucket);
    /* iterator all bucket node */
    for(i = 0; i < t_bucketcount; ++i)
    {
        /* iterator all element list for one bucket node */
        pt_node = *(_hashnode_t**)vector_at(&pt_hashtable->_vec_bucket, i);
        *(_hashnode_t**)vector_at(&pt_hashtable->_vec_bucket, i) = NULL;
        while(pt_node != NULL)
        {
            /* delete each element */
            pt_deletion = pt_node;
            pt_node = pt_node->_pt_next;

            /* destroy element */
            b_result = _GET_HASHTABLE_TYPE_SIZE(pt_hashtable);
            _GET_HASHTABLE_TYPE_DESTROY_FUNCTION(pt_hashtable)(pt_deletion->_pby_data, &b_result);
            assert(b_result);
            _alloc_deallocate(&pt_hashtable->_t_allocator,  pt_deletion, 
                _HASHTABLE_NODE_SIZE(_GET_HASHTABLE_TYPE_SIZE(pt_hashtable)), 1);
        }
    }
    
    pt_hashtable->_t_nodecount = 0;
}
Esempio n. 3
0
/* =============================================================================
 * net_isCycle
 * =============================================================================
 */
bool_t
net_isCycle (net_t* netPtr)
{
    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    long numNode = vector_getSize(nodeVectorPtr);
    long n;
    for (n = 0; n < numNode; n++) {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, n);
        nodePtr->mark = NET_NODE_MARK_INIT;
    }

    for (n = 0; n < numNode; n++) {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, n);
        switch (nodePtr->mark) {
            case NET_NODE_MARK_INIT:
                if (isCycle(nodeVectorPtr, nodePtr)) {
                    return TRUE;
                }
                break;
            case NET_NODE_MARK_DONE:
                /* do nothing */
                break;
            case NET_NODE_MARK_TEST:
                assert(0);
                break;
            default:
                assert(0);
                break;
        }
    }

    return FALSE;
}
Esempio n. 4
0
static void
tester (long geneLength, long segmentLength, long minNumSegment, bool_t doPrint)
{
    gene_t* genePtr;
    segments_t* segmentsPtr;
    random_t* randomPtr;
    bitmap_t* startBitmapPtr;
    long i;
    long j;

    genePtr = gene_alloc(geneLength);
    segmentsPtr = segments_alloc(segmentLength, minNumSegment);
    randomPtr = random_alloc();
    startBitmapPtr = bitmap_alloc(geneLength);

    random_seed(randomPtr, 0);
    gene_create(genePtr, randomPtr);
    random_seed(randomPtr, 0);
    segments_create(segmentsPtr, genePtr, randomPtr);

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

    if (doPrint) {
        printf("Gene = %s\n", genePtr->contents);
    }

    /* Check that each segment occurs in gene */
    for (i = 0; i < vector_getSize(segmentsPtr->contentsPtr); i++) {
        char *charPtr = strstr(genePtr->contents,
                               (char*)vector_at(segmentsPtr->contentsPtr, i));
        assert(charPtr != NULL);
        j = charPtr - genePtr->contents;
        bitmap_set(startBitmapPtr, j);
        if (doPrint) {
            printf("Segment %li (@%li) = %s\n",
                   i, j, (char*)vector_at(segmentsPtr->contentsPtr, i));
        }
    }

    /* Check that there is complete overlap */
    assert(bitmap_isSet(startBitmapPtr, 0));
    for (i = 0, j = 0; i < geneLength; i++ ) {
        if (bitmap_isSet(startBitmapPtr, i)) {
           assert((i-j-1) < segmentLength);
           j = i;
        }
    }

    gene_free(genePtr);
    segments_free(segmentsPtr);
    random_free(randomPtr);
    bitmap_free(startBitmapPtr);
}
Esempio n. 5
0
void test_vector_copy() {
  vector* v = create_test_vector();
  vector* copy = vector_copy(v);

  int* v_element =  (int*)vector_at(v, 5);
  int* copy_element =  (int*)vector_at(copy, 5);

  printf("v[5] = %i at %p\n", *v_element, v_element);
  printf("v[5] = %i at %p\n", *copy_element, copy_element);

  vector_free(v, NULL);
}
Esempio n. 6
0
/* =============================================================================
 * TMnet_findAncestors
 * -- Contents of bitmapPtr set to 1 if ancestor, else 0
 * -- Returns false if id is not root node (i.e., has cycle back id)
 * =============================================================================
 */
bool_t
TMnet_findAncestors (TM_ARGDECL
                     net_t* netPtr,
                     long id,
                     bitmap_t* ancestorBitmapPtr,
                     queue_t* workQueuePtr)
{
    bool_t status;

    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    assert(ancestorBitmapPtr->numBit == vector_getSize(nodeVectorPtr));

    PBITMAP_CLEARALL(ancestorBitmapPtr);
    PQUEUE_CLEAR(workQueuePtr);

    {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id);
        list_t* parentIdListPtr = nodePtr->parentIdListPtr;
        list_iter_t it;
        TMLIST_ITER_RESET(&it, parentIdListPtr);
        while (TMLIST_ITER_HASNEXT(&it, parentIdListPtr)) {
            long parentId = (long)TMLIST_ITER_NEXT(&it, parentIdListPtr);
            status = PBITMAP_SET(ancestorBitmapPtr, parentId);
            assert(status);
            status = PQUEUE_PUSH(workQueuePtr, (void*)parentId);
            assert(status);
        }
    }

    while (!PQUEUE_ISEMPTY(workQueuePtr)) {
        long parentId = (long)PQUEUE_POP(workQueuePtr);
        if (parentId == id) {
            PQUEUE_CLEAR(workQueuePtr);
            return FALSE;
        }
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, parentId);
        list_t* grandParentIdListPtr = nodePtr->parentIdListPtr;
        list_iter_t it;
        TMLIST_ITER_RESET(&it, grandParentIdListPtr);
        while (TMLIST_ITER_HASNEXT(&it, grandParentIdListPtr)) {
            long grandParentId = (long)TMLIST_ITER_NEXT(&it, grandParentIdListPtr);
            if (!PBITMAP_ISSET(ancestorBitmapPtr, grandParentId)) {
                status = PBITMAP_SET(ancestorBitmapPtr, grandParentId);
                assert(status);
                status = PQUEUE_PUSH(workQueuePtr, (void*)grandParentId);
                assert(status);
            }
        }
    }

    return TRUE;
}
Esempio n. 7
0
/* =============================================================================
 * TMnet_findDescendants
 * -- Contents of bitmapPtr set to 1 if descendants, else 0
 * -- Returns false if id is not root node (i.e., has cycle back id)
 * =============================================================================
 */
bool_t
TMnet_findDescendants (TM_ARGDECL
                       net_t* netPtr,
                       long id,
                       bitmap_t* descendantBitmapPtr,
                       queue_t* workQueuePtr)
{
    bool_t status;

    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    assert(descendantBitmapPtr->numBit == vector_getSize(nodeVectorPtr));

    PBITMAP_CLEARALL(descendantBitmapPtr);
    PQUEUE_CLEAR(workQueuePtr);

    {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id);
        list_t* childIdListPtr = nodePtr->childIdListPtr;
        list_iter_t it;
        TMLIST_ITER_RESET(&it, childIdListPtr);
        while (TMLIST_ITER_HASNEXT(&it, childIdListPtr)) {
            long childId = (long)TMLIST_ITER_NEXT(&it, childIdListPtr);
            status = PBITMAP_SET(descendantBitmapPtr, childId);
            assert(status);
            status = PQUEUE_PUSH(workQueuePtr, (void*)childId);
            assert(status);
        }
    }

    while (!PQUEUE_ISEMPTY(workQueuePtr)) {
        long childId = (long)PQUEUE_POP(workQueuePtr);
        if (childId == id) {
            queue_clear(workQueuePtr);
            return FALSE;
        }
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, childId);
        list_t* grandChildIdListPtr = nodePtr->childIdListPtr;
        list_iter_t it;
        TMLIST_ITER_RESET(&it, grandChildIdListPtr);
        while (TMLIST_ITER_HASNEXT(&it, grandChildIdListPtr)) {
            long grandChildId = (long)TMLIST_ITER_NEXT(&it, grandChildIdListPtr);
            if (!PBITMAP_ISSET(descendantBitmapPtr, grandChildId)) {
                status = PBITMAP_SET(descendantBitmapPtr, grandChildId);
                assert(status);
                status = PQUEUE_PUSH(workQueuePtr, (void*)grandChildId);
                assert(status);
            }
        }
    }

    return TRUE;
}
Esempio n. 8
0
File: net.c Progetto: takayuki/al
/* =============================================================================
 * net_findAncestors
 * -- Contents of bitmapPtr set to 1 if ancestor, else 0
 * -- Returns false if id is not root node (i.e., has cycle back id)
 * =============================================================================
 */
bool_t
net_findAncestors (net_t* netPtr,
                   long id,
                   bitmap_t* ancestorBitmapPtr,
                   queue_t* workQueuePtr)
{
    bool_t status;

    vector_t* nodeVectorPtr = LocalLoad(&netPtr->nodeVectorPtr);
    assert(LocalLoad(&ancestorBitmapPtr->numBit) == vector_getSize(nodeVectorPtr));

    bitmap_clearAll(ancestorBitmapPtr);
    queue_clear(workQueuePtr);

    {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id);
        list_t* parentIdListPtr = LocalLoad(&nodePtr->parentIdListPtr);
        list_iter_t it;
        list_iter_reset(&it, parentIdListPtr);
        while (list_iter_hasNext(&it, parentIdListPtr)) {
            long parentId = (long)list_iter_next(&it, parentIdListPtr);
            status = bitmap_set(ancestorBitmapPtr, parentId);
            assert(status);
            status = queue_push(workQueuePtr, (void*)parentId);
            assert(status);
        }
    }

    while (!queue_isEmpty(workQueuePtr)) {
        long parentId = (long)queue_pop(workQueuePtr);
        if (parentId == id) {
            queue_clear(workQueuePtr);
            return FALSE;
        }
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, parentId);
        list_t* grandParentIdListPtr = LocalLoad(&nodePtr->parentIdListPtr);
        list_iter_t it;
        list_iter_reset(&it, grandParentIdListPtr);
        while (list_iter_hasNext(&it, grandParentIdListPtr)) {
            long grandParentId = (long)list_iter_next(&it, grandParentIdListPtr);
            if (!bitmap_isSet(ancestorBitmapPtr, grandParentId)) {
                status = bitmap_set(ancestorBitmapPtr, grandParentId);
                assert(status);
                status = queue_push(workQueuePtr, (void*)grandParentId);
                assert(status);
            }
        }
    }

    return TRUE;
}
Esempio n. 9
0
/* =============================================================================
 * net_findDescendants
 * -- Contents of bitmapPtr set to 1 if descendants, else 0
 * -- Returns false if id is not root node (i.e., has cycle back id)
 * =============================================================================
 */
bool_t
net_findDescendants (net_t* netPtr,
                     long id,
                     bitmap_t* descendantBitmapPtr,
                     queue_t* workQueuePtr)
{
    bool_t status;

    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    assert(descendantBitmapPtr->numBit == vector_getSize(nodeVectorPtr));

    bitmap_clearAll(descendantBitmapPtr);
    queue_clear(workQueuePtr);

    {
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, id);
        list_t* childIdListPtr = nodePtr->childIdListPtr;
        list_iter_t it;
        list_iter_reset(&it, childIdListPtr);
        while (list_iter_hasNext(&it, childIdListPtr)) {
            long childId = (long)list_iter_next(&it, childIdListPtr);
            status = bitmap_set(descendantBitmapPtr, childId);
            assert(status);
            status = queue_push(workQueuePtr, (void*)childId);
            assert(status);
        }
    }

    while (!queue_isEmpty(workQueuePtr)) {
        long childId = (long)queue_pop(workQueuePtr);
        if (childId == id) {
            queue_clear(workQueuePtr);
            return FALSE;
        }
        net_node_t* nodePtr = (net_node_t*)vector_at(nodeVectorPtr, childId);
        list_t* grandChildIdListPtr = nodePtr->childIdListPtr;
        list_iter_t it;
        list_iter_reset(&it, grandChildIdListPtr);
        while (list_iter_hasNext(&it, grandChildIdListPtr)) {
            long grandChildId = (long)list_iter_next(&it, grandChildIdListPtr);
            if (!bitmap_isSet(descendantBitmapPtr, grandChildId)) {
                status = bitmap_set(descendantBitmapPtr, grandChildId);
                assert(status);
                status = queue_push(workQueuePtr, (void*)grandChildId);
                assert(status);
            }
        }
    }

    return TRUE;
}
Esempio n. 10
0
/* =============================================================================
 * TMremoveEdge
 * =============================================================================
 */
static void
TMremoveEdge (TM_ARGDECL  net_t* netPtr, long fromId, long toId)
{
    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    bool_t status;

    net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId);
    list_t* parentIdListPtr = childNodePtr->parentIdListPtr;
    status = TMLIST_REMOVE(parentIdListPtr, (void*)fromId);
    assert(status);

    net_node_t* parentNodePtr = (net_node_t*)vector_at(nodeVectorPtr, fromId);
    list_t* childIdListPtr = parentNodePtr->childIdListPtr;
    status = TMLIST_REMOVE(childIdListPtr, (void*)toId);
    assert(status);
}
Esempio n. 11
0
/* =============================================================================
 * isCycle
 * =============================================================================
 */
static bool_t
isCycle (vector_t* nodeVectorPtr, net_node_t* nodePtr)
{
    switch (nodePtr->mark) {
        case NET_NODE_MARK_INIT: {
            nodePtr->mark = NET_NODE_MARK_TEST;
            list_t* childIdListPtr = nodePtr->childIdListPtr;
            list_iter_t it;
            list_iter_reset(&it, childIdListPtr);
            while (list_iter_hasNext(&it, childIdListPtr)) {
                long childId = (long)list_iter_next(&it, childIdListPtr);
                net_node_t* childNodePtr =
                    (net_node_t*)vector_at(nodeVectorPtr, childId);
                if (isCycle(nodeVectorPtr, childNodePtr)) {
                    return TRUE;
                }
            }
            break;
        }
        case NET_NODE_MARK_TEST:
            return TRUE;
        case NET_NODE_MARK_DONE:
            return FALSE;
            break;
        default:
            assert(0);
    }

    nodePtr->mark = NET_NODE_MARK_DONE;
    return FALSE;
}
Esempio n. 12
0
/* =============================================================================
 * 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;
}
Esempio n. 13
0
/* =============================================================================
 * insertEdge
 * =============================================================================
 */
static void
insertEdge (net_t* netPtr, long fromId, long toId)
{
    vector_t* nodeVectorPtr = netPtr->nodeVectorPtr;
    bool_t status;

    net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId);
    list_t* parentIdListPtr = childNodePtr->parentIdListPtr;
    status = list_insert(parentIdListPtr, (void*)fromId);
    assert(status);

    net_node_t* parentNodePtr = (net_node_t*)vector_at(nodeVectorPtr, fromId);
    list_t* childIdListPtr = parentNodePtr->childIdListPtr;
    status = list_insert(childIdListPtr, (void*)toId);
    assert(status);
}
Esempio n. 14
0
/* XXX Not using */
si_t application_quit()
{
    si_t i, n;
    struct object * addr;

    /* 有多少个窗口 */
    n = vector_size(&(global_application.window_vector));

    /* 依次删除窗口 */
    for(i = n - 1; i >= 0; -- i)
    {
        addr = vector_at(&global_application.window_vector, i);

        /*
           这里没有逐个注销窗口类对象或者它的派生类对象。
           因为窗口管理程序收到用户应用程序的退出请求后,
           会释放关于这个用户应用程序的所有资源。
           */

        /* 释放这棵树 */
        object_tree_free(addr->parent);

        /* 从窗口向量中删除这个节点 */
        vector_erase(&global_application.window_vector, i);
    }

    vector_exit(&global_application.window_vector);

	event_listener_exit(&global_application.app_event_listener);
    uds_exit(&global_application.uds);

	free(global_application.name);

    return 0;
}
Esempio n. 15
0
EXPORT_SYM enum sl_error
sl_flat_map_find_pair
  (struct sl_flat_map* map, 
   const void* key, 
   struct sl_pair* pair)
{
  size_t id = 0;
  size_t len = 0;
  enum sl_error sl_err = SL_NO_ERROR;

  if(!map || !key || !pair) {
    sl_err = SL_INVALID_ARGUMENT;
    goto error;
  }
  sl_err = sl_flat_set_find(map->key_set, key, &id);
  if(sl_err != SL_NO_ERROR)
    goto error;
  SL(flat_set_length(map->key_set, &len));
  if(id == len) {
    pair->key = NULL;
    pair->data = NULL;
  } else {
    SL(vector_at(map->data_list, id, &(pair->data)));
    SL(flat_set_at(map->key_set, id, &(pair->key)));
  }
exit:
  return sl_err;
error:
  goto exit;
}
Esempio n. 16
0
static long
countData (data_t* dataPtr, vector_t* queryVectorPtr)
{
    long count = 0;
    long numQuery = vector_getSize(queryVectorPtr);

    long r;
    long numRecord = dataPtr->numRecord;
    for (r = 0; r < numRecord; r++) {
        char* record = data_getRecord(dataPtr, r);
        bool_t isMatch = TRUE;
        long q;
        for (q = 0; q < numQuery; q++) {
            query_t* queryPtr = (query_t*)vector_at(queryVectorPtr, q);
            long queryValue = queryPtr->value;
            if ((queryValue != QUERY_VALUE_WILDCARD) &&
                ((char)queryValue) != record[queryPtr->index])
            {
                isMatch = FALSE;
                break;
            }
        }
        if (isMatch) {
            count++;
        }
    }

    return count;
}
Esempio n. 17
0
static void update_view(void)
{
  struct mem_domain *d = vector_at(&domains, view_domain_index);
  if (d->size <= MEM_VIEW_SIZE || d->view_offset < 0)
    d->view_offset = 0;
  else if (d->view_offset + MEM_VIEW_SIZE > d->size)
    d->view_offset = d->size - MEM_VIEW_SIZE;
  menu_intinput_set(view_address, d->start + d->view_offset);
  strcpy(view_domain_name->text, d->name);
  view_pageup->enabled = view_pagedown->enabled = (d->size > MEM_VIEW_SIZE);
  for (int y = 0; y < MEM_VIEW_ROWS; ++y) {
    struct menu_item *row = view_rows[y];
    row->enabled = (d->view_offset + y * MEM_VIEW_COLS < d->size);
    if (row->enabled)
      sprintf(view_rows[y]->text, "%08x",
              d->start + d->view_offset + y * MEM_VIEW_COLS);
    for (int x = 0; x < MEM_VIEW_COLS; ++x) {
      int n = y * MEM_VIEW_COLS + x;
      if (n % view_data_size != 0)
        continue;
      struct menu_item *cell = view_cells[n];
      cell->enabled = (d->view_offset + n < d->size);
      if (cell->enabled)
        cell->think_proc(cell);
    }
  }
}
Esempio n. 18
0
File: net.c Progetto: takayuki/al
static void
TMremoveEdge (al_t* lock, net_t* netPtr, long fromId, long toId)
{
    vector_t* nodeVectorPtr = LocalLoad(&netPtr->nodeVectorPtr);
    bool_t status;

    net_node_t* childNodePtr = (net_node_t*)vector_at(nodeVectorPtr, toId);
    list_t* parentIdListPtr = LocalLoad(&childNodePtr->parentIdListPtr);
    status = TMLIST_REMOVE(lock, parentIdListPtr, (void*)fromId);
    assert(status);

    net_node_t* parentNodePtr = (net_node_t*)vector_at(nodeVectorPtr, fromId);
    list_t* childIdListPtr = LocalLoad(&parentNodePtr->childIdListPtr);
    status = TMLIST_REMOVE(lock, childIdListPtr, (void*)toId);
    assert(status);
}
Esempio n. 19
0
static struct member_data *get_member(struct item_data *data, int index)
{
  if (index < 0 || index >= data->members.size)
    return NULL;
  struct member_data **member_data = vector_at(&data->members, index);
  return *member_data;
}
int vector_resize(struct vector_t* v, int makeLower)
{
    int i;
    int oldData[v->size];

    for(i = 0; i < v->index; i++)
    {
        oldData[i] = vector_at(*v,i);
    }

    if(makeLower==0)
    {
        v->size *= 2;
    }
    else
    {
        v->size /= 2;
    }

    free(v->data);
    v->data = (int*) malloc(v->size * sizeof(int));

    for(i = 0; i < v->index; i++)
    {
        v->data[i] = oldData[i];
    }

    return v->size;
}
Esempio n. 21
0
/**
 * Resize.
 */
void _hashtable_resize(_hashtable_t* pt_hashtable, size_t t_resize)
{
    size_t        t_tmp = 0;
    size_t        t_pos = 0;
    size_t        i = 0;
    size_t        t_bucketcount = 0;
    _hashnode_t*  pt_node = NULL;
    _hashnode_t*  pt_nodelist = NULL;
    _hashnode_t** ppt_bucket = NULL;

    assert(pt_hashtable != NULL);

    if(t_resize > _hashtable_bucket_count(pt_hashtable))
    {
        /* select all element in hash node list */
        for(i = 0; i < vector_size(&pt_hashtable->_vec_bucket); ++i)
        {
            ppt_bucket = (_hashnode_t**)vector_at(&pt_hashtable->_vec_bucket, i);
            pt_node = *ppt_bucket;
            while(pt_node != NULL)
            {
                *ppt_bucket = pt_node->_pt_next;
                pt_node->_pt_next = pt_nodelist;
                pt_nodelist = pt_node;
                pt_node = *ppt_bucket;
            }
        }

        /* resize vector bucket */
        vector_resize(&pt_hashtable->_vec_bucket, _hashtable_get_prime(t_resize));
        t_bucketcount = _hashtable_bucket_count(pt_hashtable);

        /* rehash */
        while(pt_nodelist != NULL)
        {
            pt_node = pt_nodelist;
            pt_nodelist = pt_node->_pt_next;

            t_tmp = _GET_HASHTABLE_TYPE_SIZE(pt_hashtable);
            _hashtable_hash_auxiliary(pt_hashtable, pt_node->_pby_data, &t_tmp);
            t_pos = t_tmp % t_bucketcount;
            ppt_bucket = (_hashnode_t**)vector_at(&pt_hashtable->_vec_bucket, t_pos);
            pt_node->_pt_next = *ppt_bucket;
            *ppt_bucket = pt_node;
        }
    }
}
Esempio n. 22
0
void fdset_populate(fdset *fds, fd_set *fset, vector *v) {
    int i;
    for (i = 0; i < vector_size(v); ++i) {
        select_event_t *pse = (select_event_t*)(vector_at(v, i));
        FD_SET(pse->fd, fset);
        fds->max_fd = (pse->fd > fds->max_fd ? pse->fd : fds->max_fd);
    }
}
Esempio n. 23
0
/* =============================================================================
 * segments_free
 * =============================================================================
 */
void
segments_free (segments_t* segmentsPtr)
{
    SEQ_FREE(vector_at(segmentsPtr->contentsPtr, 0));
    vector_free(segmentsPtr->contentsPtr);
    SEQ_FREE(segmentsPtr->strings);
    SEQ_FREE(segmentsPtr);
}
Esempio n. 24
0
/**
 * Access last vector data.
 */
void* vector_back(const vector_t* cpvec_vector)
{
    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));
    assert(!vector_empty(cpvec_vector));

    return vector_at(cpvec_vector, vector_size(cpvec_vector) - 1);
}
Esempio n. 25
0
/**
 * Access first vector data.
 */
void* vector_front(const vector_t* cpvec_vector)
{
    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));
    assert(!vector_empty(cpvec_vector));

    return vector_at(cpvec_vector, 0);
}
Esempio n. 26
0
/* =============================================================================
 * segments_free
 * =============================================================================
 */
void
segments_free (segments_t* segmentsPtr)
{
    free(vector_at(segmentsPtr->contentsPtr, 0));
    vector_free(segmentsPtr->contentsPtr);
    free(segmentsPtr->strings);
    free(segmentsPtr);
}
Esempio n. 27
0
//获得目标快捷方式指针
void find_running_shortcut(){
	int find_num=0;  //查找正在作用的桌面图标
	for(find_num=0; find_num < app_number; find_num++){
		sh_temp_ptr = vector_at(&sh_desktop_vector, find_num);
		if(sh_temp_ptr->flag==1)
			break;
	}
}
Esempio n. 28
0
/* =============================================================================
 * net_getChildIdListPtr
 * =============================================================================
 */
list_t*
net_getChildIdListPtr (net_t* netPtr, long id)
{
    net_node_t* nodePtr = (net_node_t*)vector_at(netPtr->nodeVectorPtr, id);
    assert(nodePtr);

    return nodePtr->childIdListPtr;
}
Esempio n. 29
0
static void watchfile_destroy(void)
{
  for (int i = 0; i < watchfile_entries.size; ++i) {
    struct watchfile_entry *entry = vector_at(&watchfile_entries, i);
    free(entry->name);
    adex_destroy(&entry->adex);
  }
  vector_destroy(&watchfile_entries);
}
Esempio n. 30
0
si_t window_manager_get_app_index(struct application_info* ptr)
{
	int i;
	i = vector_size(&global_wm.application_info_vector);
	while(--i >= 0)
		if((int)vector_at(&global_wm.application_info_vector, i) == (int)ptr)
			return i;
	return -1;
}