Ejemplo n.º 1
0
/**
 * Assign vector with variable argument list of specificed element.
 */
void _vector_assign_elem_varg(vector_t* pvec_vector, size_t t_count, va_list val_elemlist)
{
    iterator_t it_iter;
    iterator_t it_begin;
    iterator_t it_end;
    bool_t     b_result = false;
    void*      pv_varg = NULL;

    assert(pvec_vector != NULL);
    assert(_vector_is_inited(pvec_vector));

    /* get value from varg */
    pv_varg = _alloc_allocate(&pvec_vector->_t_allocator, _GET_VECTOR_TYPE_SIZE(pvec_vector), 1);
    assert(pv_varg != NULL);
    _vector_get_varg_value_auxiliary(pvec_vector, val_elemlist, pv_varg);

    /* copy value from varg for each element */
    vector_resize(pvec_vector, t_count);
    it_begin = vector_begin(pvec_vector);
    it_end = vector_end(pvec_vector);
    for (it_iter = it_begin; !iterator_equal(it_iter, it_end); it_iter = iterator_next(it_iter)) {
        b_result = _GET_VECTOR_TYPE_SIZE(pvec_vector);
        _GET_VECTOR_TYPE_COPY_FUNCTION(pvec_vector)(_VECTOR_ITERATOR_COREPOS(it_iter), pv_varg, &b_result);
        assert(b_result);
    }

    /* destroy varg and free memory */
    _vector_destroy_varg_value_auxiliary(pvec_vector, pv_varg);
    _alloc_deallocate(&pvec_vector->_t_allocator, pv_varg, _GET_VECTOR_TYPE_SIZE(pvec_vector), 1);
}
void vector_push_back(struct vector_t* v, int value) {
    if(v->index >= v->size)
    {
        vector_resize(v, 0);
    }
    v->data[v->index++] = value;
}
Ejemplo n.º 3
0
Archivo: fasl.c Proyecto: mschaef/vcsh
static void fasl_ensure_valid_table_index(lref_t reader, size_t index)
{
    if (NULLP(FASL_READER_STREAM(reader)->table))
    {
        FASL_READER_STREAM(reader)->table =
            vectorcons((index >=
                        DEFAULT_FASL_TABLE_SIZE) ? index +
                       DEFAULT_FASL_TABLE_SIZE : DEFAULT_FASL_TABLE_SIZE, NIL);
    }
    else
    {
        lref_t fasl_table = FASL_READER_STREAM(reader)->table;
        assert(VECTORP(fasl_table));
        size_t old_len = fasl_table->as.vector.dim;

        if (index >= old_len)
        {
            size_t new_len =
                (index >= old_len * 2) ? index + DEFAULT_FASL_TABLE_SIZE : (old_len * 2);

            FASL_READER_STREAM(reader)->table =
                vector_resize(fasl_table, new_len > SIZE_MAX ? SIZE_MAX : (size_t) new_len, NIL);
        }
    }

    assert(VECTORP(FASL_READER_STREAM(reader)->table));
    assert(index < (FASL_READER_STREAM(reader)->table)->as.vector.dim);
}
Ejemplo n.º 4
0
/**
 * Assign vector element with an exist vector container range.
 */
void vector_assign_range(vector_t* pvec_vector, vector_iterator_t it_begin, vector_iterator_t it_end)
{
    iterator_t it_dest;
    iterator_t it_src;
    bool_t     b_result = false;

    /* assign the two iterator is as the same type as pvec_vector */
    assert(pvec_vector != NULL);
    assert(_vector_is_inited(pvec_vector));
    /*assert(!_vector_iterator_belong_to_vector(pvec_vector, it_begin));*/
    /*assert(!_vector_iterator_belong_to_vector(pvec_vector, it_end));*/
    assert(_vector_same_vector_iterator_type(pvec_vector, it_begin));
    assert(_vector_same_vector_iterator_type(pvec_vector, it_end));
    assert(iterator_equal(it_begin, it_end) || _vector_iterator_before(it_begin, it_end));

    /* copy value from range [it_begin, it_end) for each element */
    vector_resize(pvec_vector, iterator_distance(it_begin, it_end));
    for(it_dest = vector_begin(pvec_vector), it_src = it_begin;
        !iterator_equal(it_dest, vector_end(pvec_vector)) && !iterator_equal(it_src, it_end);
        it_dest = iterator_next(it_dest), it_src = iterator_next(it_src))
    {
        b_result = _GET_VECTOR_TYPE_SIZE(pvec_vector);
        _GET_VECTOR_TYPE_COPY_FUNCTION(pvec_vector)(_VECTOR_ITERATOR_COREPOS(it_dest), _VECTOR_ITERATOR_COREPOS(it_src), &b_result);
        assert(b_result);
    }
    assert(iterator_equal(it_dest, vector_end(pvec_vector)) && iterator_equal(it_src, it_end));
}
Ejemplo n.º 5
0
JNIEXPORT void JNICALL Java_neuron_Neuron_vectorToHoc
  (JNIEnv *env, jclass, jlong jc, jdoubleArray ja, jint size) {
	Object* ho = (Object*)jc;
	Vect* vec = (Vect*)ho->u.this_pointer;
	vector_resize(vec, size);
	env->GetDoubleArrayRegion(ja, 0, size, &vec->elem(0));
}
Ejemplo n.º 6
0
void vector_add(vector *vec, void *item) {
    if ( vec->size == vec->total )          // It's full
        vector_resize(vec, 2 * vec->total );
    
    vec->item[vec->size] = item;
    vec->size++;
}
Ejemplo n.º 7
0
size_t vector_push(struct vec *v, int item) {
    if (v->sz == v->capacity)
	if (!vector_resize(v)) return -1;

    v->vals[v->sz++] = item;
    return (v->sz - 1);
}
Ejemplo n.º 8
0
/*
 * Given a string, split it at any of the provided separators to form a
 * vector, copying each string segment.  If the third argument isn't NULL,
 * reuse that vector; otherwise, allocate a new one.  Any number of
 * consecutive separators are considered a single separator.
 */
struct vector *
vector_split_multi(const char *string, const char *seps,
                   struct vector *vector)
{
    const char *p, *start;
    size_t i, count;

    vector = vector_reuse(vector);

    count = split_multi_count(string, seps);
    if (vector->allocated < count)
        vector_resize(vector, count);

    for (start = string, p = string, i = 0; *p != '\0'; p++)
        if (strchr(seps, *p) != NULL) {
            if (start != p)
                vector->strings[i++] = xstrndup(start, p - start);
            start = p + 1;
        }
    if (start != p)
        vector->strings[i++] = xstrndup(start, p - start);
    vector->count = i;

    return vector;
}
Ejemplo n.º 9
0
//inserts obj into a new space at the end of v
void vector_append(Vector *v, LispObject *obj) {
    if(v->size >= v->array_size)
        vector_resize(v, 2);
    v->array[v->end % v->array_size] = obj;
    v->end++;
    v->size++;
}
int vector_pop_back(struct vector_t* v) {
    if(v->index > -1)
    {
        vector_resize(v);
        return v->data[--v->index];
    }
    return -1;
}
Ejemplo n.º 11
0
/*
 * Given a vector and a path to a program, exec that program with the vector
 * as its arguments.  This requires adding a NULL terminator to the vector and
 * casting it appropriately.
 */
int
vector_exec(const char *path, struct vector *vector)
{
    if (vector->allocated == vector->count)
        vector_resize(vector, vector->count + 1);
    vector->strings[vector->count] = NULL;
    return execv(path, (char * const *) vector->strings);
}
Ejemplo n.º 12
0
void vector_push(Vector *vec, size_t elem)
{
	if (vec->size >= vec->cap)
		vector_resize(vec);
	
	vec->data[vec->size] = elem;
	vec->size++;
}
Ejemplo n.º 13
0
Archivo: vector.c Proyecto: ox/vector
void * vector_pop(struct Vector * vector) {
  if (vector->population == 0) {
    return NULL;
  }

  void * elem = vector->storage[--vector->population];
  vector_resize(vector);
  return elem;
}
Ejemplo n.º 14
0
/**
 * Initialize hashtable container.
 */
void _hashtable_init(_hashtable_t* pt_hashtable, size_t t_bucketcount, ufun_t ufun_hash, bfun_t bfun_compare)
{
    assert(pt_hashtable != NULL);
    assert(_hashtable_is_created(pt_hashtable));

    /* initialize the bucket vector and node count */
    vector_init(&pt_hashtable->_vec_bucket);
    if (t_bucketcount > 0) {
        vector_resize(&pt_hashtable->_vec_bucket, _hashtable_get_prime(t_bucketcount));
    } else {
        vector_resize(&pt_hashtable->_vec_bucket, _hashtable_get_prime(_HASHTABLE_DEFAULT_BUCKET_COUNT));
    }
    pt_hashtable->_t_nodecount = 0;

    /* initialize the hash, compare and destroy element function */
    pt_hashtable->_ufun_hash = ufun_hash != NULL ? ufun_hash : _hashtable_default_hash;
    pt_hashtable->_bfun_compare = bfun_compare != NULL ? bfun_compare : _GET_HASHTABLE_TYPE_LESS_FUNCTION(pt_hashtable);
}
Ejemplo n.º 15
0
void
vector_init(vector *vec, size_t size)
{
	vec->array = checked_malloc(INIT_SIZE * size);
	vec->element_size = size;
	vec->length = 0;
	vec->max_length = INIT_SIZE;
	vector_resize(vec);
}
Ejemplo n.º 16
0
// ----------------------------------------------------------------------------
vertex_buffer_t *
vertex_buffer_new_from_data( const char *format,
                             size_t vcount,
                             void *vertices,
                             size_t icount,
                             GLuint *indices )
{
    vertex_buffer_t *self = vertex_buffer_new( format );

    vector_resize( self->vertices, vcount );
    assert( self->vertices->size == vcount);
    memcpy( self->vertices->items, vertices, vcount*self->vertices->item_size );
    vector_resize( self->indices, icount );
    assert( self->indices->size == icount);
    memcpy( self->indices->items, indices, icount*self->indices->item_size );
    self->dirty = 1;
    return self;
}
Ejemplo n.º 17
0
/*
 * Add a new counted string to the vector, resizing the vector as necessary
 * the same as with vector_add.  This function is only available for vectors,
 * not cvectors, since it requires the duplication of the input string to be
 * sure it's nul-terminated.
 */
void
vector_addn(struct vector *vector, const char *string, size_t length)
{
    size_t next = vector->count;

    if (vector->count == vector->allocated)
        vector_resize(vector, vector->allocated + 1);
    vector->strings[next] = xstrndup(string, length);
    vector->count++;
}
Ejemplo n.º 18
0
void
vector_append(vector *vec, void *obj, size_t size)
{
	if (size != vec->element_size) {
		fprintf(stderr, "Error: vector_append: unmatched type size.\n");
		exit(1);
	}
	memcpy(vec->array + vec->length * vec->element_size, obj, size);
	vec->length++;
	vector_resize(vec);
}
Ejemplo n.º 19
0
vector getFileMask(WaveFile* waveFile, vector wave, int len, char marker = NULL)
{
    vector mask;

    ListChunk * listLablChunk = NULL;
    ListChunk * listLtxtChunk = NULL;

    qDebug() << "listCount " << waveFile->listCount << LOG_DATA;

    for (int i=0; i<waveFile->listCount; i++)
    {
        ListChunk * listChunk = &(waveFile->listChunks[i]);
        if (listChunk == NULL) continue;

        qDebug() << "listChunk->lablCount " << listChunk->lablCount << LOG_DATA;
        if (listChunk->lablChunks != NULL && listChunk->lablCount > 0)
        {
            listLablChunk = listChunk;
        }

        qDebug() << "listChunk->ltxtCount " << listChunk->ltxtCount << LOG_DATA;
        if (listChunk->ltxtChunks != NULL && listChunk->ltxtCount > 0)
        {
            listLtxtChunk = listChunk;
        }
    }

    bool tryFileData = (waveFile->cueChunk != NULL)
            && (littleEndianBytesToUInt16(waveFile->cueChunk->cuePointsCount) > 0)
            && (listLtxtChunk != NULL)
            && (listLtxtChunk->ltxtChunks != NULL)
            && (listLtxtChunk->ltxtCount > 0)
            && (listLablChunk != NULL)
            && (listLablChunk->lablChunks != NULL)
            && (listLablChunk->lablCount > 0);

    if (tryFileData)
    {
        qDebug() << "tryFileData" << LOG_DATA;
        vector mask_from_file = readMaskFromFile(waveFile, wave.x, marker);
        vector mask_norm = normalizev(mask_from_file, MASK_MIN, MASK_MAX);
        mask = vector_resize(mask_norm, len);
        freev(mask_norm);
        freev(mask_from_file);
        qDebug() << "vector_resize" << LOG_DATA;
    }

    if (!tryFileData || !validateMask(mask)) {
        qDebug() << "!tryFileData" << LOG_DATA;
        mask = onesv(len);
    }

    return mask;
}
Ejemplo n.º 20
0
int vector_set(vector *v, int index, int item) 
{
	assert(v!=NULL);
	if ( index >= v->n_items ) { 
		vector_resize(v, index+8);
	}
	if ( index < v->n_items ) { 
		v->items[index] = item;
	}
	return index < v->n_items;
}
Ejemplo n.º 21
0
void vector_set(Vector *vector, size_t index, Data value)
{
	if (index > 0 && vector->size >= index) {
		vector->container[index] = value;
		vector->vSize = index + 1;
	}
	else {
		vector_resize(vector, index + 1);
		vector->container[index] = value;
	}
}
Ejemplo n.º 22
0
void *_vector_push(struct vector *v, size_t elemsize)
{
	if (v->count == v->allocated_count) {
		if (!vector_grow(v)) {
			return NULL;
		}
	}

	vector_resize(v, v->count+1);
	return _vector_get(v, elemsize, v->count-1);
}
int vector_pop_back(struct vector_t* v) {
    if(v->index <= 0)
    {
        return INT_MAX;
    }
    if(v->index <= v->size / 2)
    {
        vector_resize(v, 1);
    }

    return v->data[--v->index];
}
Ejemplo n.º 24
0
//TODO: Do we care that this can fail?
void stack_push(struct stack *stack, void *elem)
{
    if (!stack || !elem)
        return;

    if (stack->index == stack->vec.len) {
        vector_resize(&stack->vec, stack->index * 2);
    }

    vector_set(&stack->vec, stack->index, elem);
    stack->index++;
}
Ejemplo n.º 25
0
Archivo: test.c Proyecto: esheldon/misc
void test_realloc_resize() {
    size_t n=10;
    struct vector* v = vector_new(n, sizeof(struct test));

    assert(v->size == n);
    assert(v->capacity == n);

    size_t new_n = 12;
    vector_realloc(v, new_n);
    assert(v->size == n);
    assert(v->capacity == new_n);

    new_n = 7;
    vector_realloc(v, new_n);
    assert(v->size == new_n);
    assert(v->capacity == new_n);

    size_t rsn = 6;
    vector_resize(v,rsn);
    assert(v->size == rsn);
    assert(v->capacity == new_n);

    rsn = 12;
    vector_resize(v,rsn);
    assert(v->size == rsn);
    assert(v->capacity == rsn);

    vector_clear(v);
    assert(v->size == 0);
    assert(v->capacity == rsn);

    vector_freedata(v);
    assert(v->size == 0);
    assert(v->capacity == 0);
    assert(v->d == NULL);

    v = vector_delete(v);
    assert(v == NULL);
}
Ejemplo n.º 26
0
void vector_push_back(vector_t *v, void *e)
{
    void *base = v->finish;
    v->finish += v->element_sz;

    if(v->finish == v->end)
    {
        vector_resize(v);
        base = v->finish - v->element_sz;
    }

    memcpy(base, e, v->element_sz);
}
Ejemplo n.º 27
0
int lp_add_var_without_A(LP* lp, char* name) {
  /* 追加されるのは非負変数       */
  /* 戻り値は追加された変数の番号 */
  /* 応急処置です... matrix_add_column(lp->A) しない以外は lp_add_var()
     と同じです. */
  lp->vars ++;

  lp->var_type = my_realloc(lp->var_type, lp->vars*sizeof(int));
  lp->var_type[lp->vars-1] = LP_VAR_TYPE_NORMAL;

  if(name != NULL) {
    lp->var_name = my_realloc(lp->var_name, lp->vars*sizeof(char*));
    lp->var_name[lp->vars-1] = my_malloc(LP_NAME_LEN_MAX*sizeof(char));
    if (name == NULL || name[0] == 0) {
      snprintf(lp->var_name[lp->vars-1], LP_NAME_LEN_MAX,
               "v%d", lp->vars);
    } else {
      strncpy(lp->var_name[lp->vars-1], name, LP_NAME_LEN_MAX);
    }
    hash_str_find(lp->hash_str_var_name, name, lp->var_name, lp->vars-1);
  }

  vector_resize(lp->x, lp->vars);
  vector_resize(lp->c, lp->vars);
  vector_resize(lp->c_back, lp->vars);

  lp->is_basis   = my_realloc(lp->is_basis,   lp->vars*sizeof(int));
  lp->is_integer = my_realloc(lp->is_integer, lp->vars*sizeof(int));

  lp->upper.is_valid = my_realloc(lp->upper.is_valid, lp->vars*sizeof(int));
  lp->lower.is_valid = my_realloc(lp->lower.is_valid, lp->vars*sizeof(int));
  lp->upper.bound = my_realloc(lp->upper.bound, lp->vars*sizeof(mpq_t));
  lp->lower.bound = my_realloc(lp->lower.bound, lp->vars*sizeof(mpq_t));
  lp->upper.is_valid[lp->vars-1] = FALSE;
  lp->lower.is_valid[lp->vars-1] = TRUE;
  mpq_init(lp->lower.bound[lp->vars-1]);

  return lp->vars-1;
}
Ejemplo n.º 28
0
vector data_get_intensive_cutted(SimpleGraphData * data)
{
    if (data->b_intensive_cutted == 0)
    {
        vector intensive = data_get_intensive(data);
        vector pitch_log = data_get_pitch_log(data);
        vector resized_pitch_log = vector_resize(pitch_log, intensive.x);
        data->d_intensive_cutted = vector_cut_by_mask(intensive, resized_pitch_log);
        freev(resized_pitch_log);

        data->b_intensive_cutted = 1;
    }
    return data->d_intensive_cutted;
}
int vector_pop_back(struct vector_t* v) {

	if(v->index==0)
	{
		printf("No elements left !\n");
		return -1;
	}
	else 
		if(v->index < (v->size/2))
		vector_resize(v);
	if(v->index!=0)
	return v->data[--v->index];

}
Ejemplo n.º 30
0
struct stack *stack_create(size_t size)
{
    struct stack *stack;

    stack = calloc(1, sizeof(*stack));
    
    if (!stack)
        return NULL;
            
    stack->vec.size = size;
    vector_resize(&stack->vec, 1);

    return stack;
}