예제 #1
0
파일: table.c 프로젝트: mity/mctrl
table_t*
table_create(WORD col_count, WORD row_count)
{
    table_t* table;

    TABLE_TRACE("table_create(%hd, %hd)", col_count, row_count);

    table = (table_t*) malloc(sizeof(table_t));
    if(MC_ERR(table == NULL)) {
        MC_TRACE("table_create: malloc() failed.");
        return NULL;
    }

    table->refs = 1;
    table->col_count = 0;
    table->row_count = 0;
    table->cols = NULL;
    table->rows = NULL;
    table->cells = NULL;

    view_list_init(&table->vlist);

    if(MC_ERR(table_resize(table, col_count, row_count) != 0)) {
        MC_TRACE("table_create: table_resize() failed.");
        free(table);
        return NULL;
    }

    return table;
}
예제 #2
0
파일: grid.c 프로젝트: UIKit0/mctrl
static int
grid_resize_table(grid_t* grid, WORD col_count, WORD row_count)
{
    GRID_TRACE("grid_resize_table(%d, %d)", (int) col_count, (int) row_count);

    if(grid->table != 0) {
        if(MC_ERR(table_resize(grid->table, col_count, row_count) != 0)) {
            MC_TRACE("grid_resize_table: table_resize() failed.");
            return -1;
        }
    } else {
        if(grid->col_widths != NULL)
            grid_alloc_col_widths(grid, grid->col_count, col_count, TRUE);
        if(grid->row_heights)
            grid_alloc_row_heights(grid, grid->row_count, row_count, TRUE);

        grid->col_count = col_count;
        grid->row_count = row_count;

        if(!grid->no_redraw) {
            InvalidateRect(grid->win, NULL, TRUE);
            grid_setup_scrollbars(grid, TRUE);
        }
    }

    return 0;
}
예제 #3
0
파일: table.c 프로젝트: mity/mctrl
BOOL MCTRL_API
mcTable_Resize(MC_HTABLE hTable, WORD wColumnCount, WORD wRowCount)
{
    if(MC_ERR(table_resize(hTable, wColumnCount, wRowCount) != 0)) {
        MC_TRACE("mcTable_Resize: table_resize() failed.");
        return FALSE;
    }

    return TRUE;
}
예제 #4
0
파일: table.c 프로젝트: def44/mate
int table_put_aux(struct table *t, struct object *k, struct object *v, int hash) {
	int value, n, old_value;
	struct table_entry *new_entry, *r;

	n = hash % t->current_capacity;
	old_value = 0;

	for (r = t->buckets[n]; r != NULL; r = r->next) {
		value = table_run_equals(t, k, heap_fetch_object(heap, r->key));
		if (value == 1)
			break;

#ifdef DMP
		if (t->dmp != NULL)
			table_dmp_load(t->dmp);
#endif
	}

#ifdef DMP
	if (t->dmp != NULL)
		table_dmp_store(t->dmp);
#endif

	/* lock */
	table_wrlock(t);

	if (r != NULL) {
		old_value = r->value;
		r->key = object_get_ref(k);
		r->value = object_get_ref(v);
		r->hash = hash;
	} else {
		if ((new_entry =
		     table_entry_create(object_get_ref(k), object_get_ref(v), hash)) == NULL) {
			mvm_halt();
		}

		new_entry->next = t->buckets[n];
		t->buckets[n] = new_entry;
		t->num_entries++;
	}

	if (table_entries_exceeds_load_factor(t->num_entries,
					      t->load_factor,
					      t->current_capacity)) {
		table_resize(t, t->current_capacity*2, &t);
		object_set_table(t->object, t);
	}

	/* unlock */
	table_unlock(t);

	return old_value;
}
예제 #5
0
파일: table.c 프로젝트: def44/mate
int table_put(struct table *t, struct object *k, struct object *v) {
	int hash;

	if (t == NULL) {
		fprintf(stderr, "mvm: table not initialized!\n");
		mvm_halt();
	}

#ifdef DMP
	if (t->dmp != NULL)
		table_dmp_load(t->dmp);
#endif

	/* lock */
	table_rdlock(t);

	/* check if iterator is running */
	if (t->iterator_is_running == 1) {
		fprintf(stderr, "mvm: cannot put, Table's iterator is running!\n");
		mvm_halt();
	}

	/* unlock */
	table_unlock(t);

	hash = abs(table_run_hash_code(t, k));

#ifdef DMP
	if (t->dmp != NULL)
		table_dmp_load(t->dmp);
#endif

	/* lock */
	table_rdlock(t);

	if (t->current_capacity <= 0) {
		table_resize(t, TABLE_DEFAULT_INITIAL_CAPACITY, &t);
	}

	/* unlock */
	table_unlock(t);

#ifdef DMP
	if (t->dmp != NULL)
		table_dmp_load(t->dmp);
#endif

	return table_put_aux(t, k, v, hash);
}
예제 #6
0
파일: hash.c 프로젝트: alepharchives/glean
static int table_grow(table *t) {
        int gsz = next_sz(t->sz);
        if (gsz > t->ms || gsz == t->sz) return TABLE_FULL;
        return table_resize(t, gsz);
}