Exemplo n.º 1
0
void init_pred_table(pred_table_t *pred_table){
	int32_t size = INIT_PRED_TABLE_SIZE;
	if (size >= MAXSIZE(sizeof(pred_entry_t), 0)){
		out_of_memory();
	}
	pred_table->evpred_tbl.size = size;
	pred_table->evpred_tbl.num_preds = 1;
	pred_table->evpred_tbl.entries = (pred_entry_t*)
		safe_malloc(size*sizeof(pred_entry_t));
	pred_table->pred_tbl.size = size;
	pred_table->pred_tbl.num_preds = 1;
	pred_table->pred_tbl.entries = (pred_entry_t*)
		safe_malloc(size*sizeof(pred_entry_t));
	init_stbl(&(pred_table->pred_name_index), size);
	stbl_add(&(pred_table->pred_name_index), truepred, 0);
	pred_table->pred_tbl.entries[0].arity = 0;
	pred_table->pred_tbl.entries[0].name = truepred;
	pred_table->pred_tbl.entries[0].signature = NULL;
	pred_table->pred_tbl.entries[0].size_atoms = 0;
	pred_table->pred_tbl.entries[0].num_atoms = 0;
	pred_table->pred_tbl.entries[0].atoms = NULL;
	pred_table->evpred_tbl.entries[0].arity = 0;
	pred_table->evpred_tbl.entries[0].name = truepred;
	pred_table->evpred_tbl.entries[0].signature = NULL;
	pred_table->evpred_tbl.entries[0].size_atoms = 0;
	pred_table->evpred_tbl.entries[0].num_atoms = 0;
	pred_table->evpred_tbl.entries[0].atoms = NULL;

}
Exemplo n.º 2
0
void init_atom_table(atom_table_t *table) {
	uint32_t i;

	table->size = INIT_ATOM_TABLE_SIZE;
	table->num_vars = 0; //atoms are positive
	table->num_unfixed_vars = 0;
	if (table->size >= MAXSIZE(sizeof(samp_atom_t *), 0)){
		out_of_memory();
	}
	table->atom = (samp_atom_t **) safe_malloc(table->size * sizeof(samp_atom_t *));
	table->active = (bool *) safe_malloc(table->size * sizeof(bool));
	table->assignments[0] = (samp_truth_value_t *)
		safe_malloc(table->size * sizeof(samp_truth_value_t));
	table->assignments[1] = (samp_truth_value_t *)
		safe_malloc(table->size * sizeof(samp_truth_value_t));
	table->assignment_index = 0;
	table->assignment = table->assignments[table->assignment_index];
	table->pmodel = (int32_t *) safe_malloc(table->size * sizeof(int32_t));
	table->sampling_nums = (int32_t *) safe_malloc(table->size * sizeof(int32_t));

	for (i = 0; i < table->size; i++) {
		table->pmodel[i] = 0;//was -1
	}
	table->num_samples = 0;
	init_array_hmap(&table->atom_var_hash, ARRAY_HMAP_DEFAULT_SIZE);
	//  table->entries[0].atom = (samp_atom_t *) safe_malloc(sizeof(samp_atom_t));
	//  table->entries[0].atom->pred = 0;
}
Exemplo n.º 3
0
static void sort_table_resize(sort_table_t *sort_table, uint32_t n){
	if (n >= MAXSIZE(sizeof(sort_entry_t), 0)){
		out_of_memory();
	}
	sort_table->entries = (sort_entry_t *) safe_realloc(sort_table->entries,
			n * sizeof(sort_entry_t));
	sort_table->size = n; 
}
Exemplo n.º 4
0
static void var_table_resize(var_table_t *var_table, uint32_t n){
	if (n >= MAXSIZE(sizeof(var_entry_t), 0)){
		out_of_memory();
	}
	var_table->entries = (var_entry_t *) safe_realloc(var_table->entries,
			n * sizeof(var_entry_t));
	var_table->size = n; 
}
Exemplo n.º 5
0
static void const_table_resize(const_table_t *const_table, uint32_t n){
	if (n >= MAXSIZE(sizeof(const_entry_t), 0)){
		out_of_memory();
	}
	const_table->entries = (const_entry_t *) safe_realloc(const_table->entries,
			n * sizeof(const_entry_t));
	const_table->size = n; 
}
Exemplo n.º 6
0
void init_rule_table(rule_table_t *table){
	table->size = INIT_RULE_TABLE_SIZE;
	table->num_rules = 0;
	if (table->size >= MAXSIZE(sizeof(samp_rule_t *), 0)){
		out_of_memory();
	}
	table->samp_rules =
		(samp_rule_t **) safe_malloc(table->size * sizeof(samp_rule_t *));
}
Exemplo n.º 7
0
void init_source_table(source_table_t *table) {
	table->size = INIT_SOURCE_TABLE_SIZE;
	table->num_entries = 0;
	if (table->size >= MAXSIZE(sizeof(source_entry_t *), 0)) {
		out_of_memory();
	}
	table->entry = (source_entry_t **)
		safe_malloc(table->size * sizeof(source_entry_t *));
}
Exemplo n.º 8
0
void init_query_instance_table(query_instance_table_t *table) {
	table->size = INIT_QUERY_INSTANCE_TABLE_SIZE;
	table->num_queries = 0;
	if (table->size >= MAXSIZE(sizeof(samp_query_instance_t *), 0)) {
		out_of_memory();
	}
	table->query_inst = (samp_query_instance_t **)
		safe_malloc(table->size * sizeof(samp_query_instance_t *));
}
Exemplo n.º 9
0
void init_const_table(const_table_t *const_table){
	int32_t size = INIT_CONST_TABLE_SIZE;
	if (size >= MAXSIZE(sizeof(const_entry_t), 0)){
		out_of_memory();
	}
	const_table->size = size;
	const_table->num_consts = 0;
	const_table->entries = (const_entry_t*)
		safe_malloc(size*sizeof(const_entry_t));
	init_stbl(&(const_table->const_name_index), 0);
}
Exemplo n.º 10
0
void init_var_table(var_table_t *var_table){
	int32_t size = INIT_VAR_TABLE_SIZE;
	if (size >= MAXSIZE(sizeof(var_entry_t), 0)){
		out_of_memory();
	}
	var_table->size = size;
	var_table->num_vars = 0;
	var_table->entries = (var_entry_t*)
		safe_malloc(size*sizeof(var_entry_t));
	init_stbl(&(var_table->var_name_index), 0);
}
Exemplo n.º 11
0
void query_instance_table_resize(query_instance_table_t *table) {
	int32_t size = table->size;
	int32_t num_queries = table->num_queries;
	if (num_queries + 1 < size) return;
	if (MAXSIZE(sizeof(samp_query_instance_t *), 0) - size <= (size/2)) {
		out_of_memory();
	}
	size += size/2;
	table->query_inst = (samp_query_instance_t **)
		safe_realloc(table->query_inst, size * sizeof(samp_query_instance_t *));
	table->size = size; 
}
Exemplo n.º 12
0
void source_table_extend(source_table_t *table) {
	int32_t size = table->size;
	int32_t num_entries = table->num_entries;
	if (num_entries + 1 < size) return;
	if (MAXSIZE(sizeof(source_entry_t *), 0) - size <= (size/2)) {
		out_of_memory();
	}
	size += size/2;
	table->entry = (source_entry_t **)
		safe_realloc(table->entry, size * sizeof(source_entry_t *));
	table->size = size; 
}
Exemplo n.º 13
0
static void pred_tbl_resize(pred_tbl_t *pred_tbl){//call this extend, not resize
	int32_t size = pred_tbl->size;
	int32_t num_preds = pred_tbl->num_preds;
	if (num_preds < size) return;
	if (MAXSIZE(sizeof(pred_entry_t), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	pred_tbl->entries = (pred_entry_t *) safe_realloc(pred_tbl->entries,
			size * sizeof(pred_entry_t));
	pred_tbl->size = size; 
}
Exemplo n.º 14
0
/*
 * Resize the rule table to be at least 1 more than num_rules
 */
void rule_table_resize(rule_table_t *rule_table){
	int32_t size = rule_table->size;
	int32_t num_rules = rule_table->num_rules;
	if (num_rules < size) return;
	if (MAXSIZE(sizeof(samp_rule_t *), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	rule_table->samp_rules = (samp_rule_t **)
		safe_realloc(rule_table->samp_rules,
				size * sizeof(samp_rule_t *));
	rule_table->size = size; 
}
Exemplo n.º 15
0
/*
 * Resizes the atom table to fit the current atom_table->num_vars. When
 * atom_table is resized, the assignments and the watched literals must also be
 * resized. 
 */
void atom_table_resize(atom_table_t *atom_table, rule_inst_table_t *rule_inst_table) {
	int32_t size, num_vars, i;

	num_vars = atom_table->num_vars;
	size = atom_table->size;
	if (num_vars < size) return;

	if (MAXSIZE(sizeof(samp_atom_t *), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	atom_table->atom = (samp_atom_t **)
		safe_realloc(atom_table->atom, size * sizeof(samp_atom_t *));
	atom_table->active = (bool *)
		safe_realloc(atom_table->active, size * sizeof(bool));
	atom_table->sampling_nums = (int32_t *)
		safe_realloc(atom_table->sampling_nums, size * sizeof(int32_t));
	atom_table->assignments[0] = (samp_truth_value_t *) 
		safe_realloc(atom_table->assignments[0], size * sizeof(samp_truth_value_t));
	atom_table->assignments[1] = (samp_truth_value_t *) 
		safe_realloc(atom_table->assignments[1], size * sizeof(samp_truth_value_t));
	atom_table->assignment = atom_table->assignments[atom_table->assignment_index];
	atom_table->pmodel = (int32_t *)
		safe_realloc(atom_table->pmodel, size * sizeof(int32_t));

	if (MAXSIZE(sizeof(samp_clause_t *), 0) - size <= size){
		out_of_memory();
	}
	rule_inst_table->watched = (samp_clause_list_t *) safe_realloc(
			rule_inst_table->watched, 2 * size * sizeof(samp_clause_list_t));

	for (i = atom_table->size; i < size; i++) {
		atom_table->pmodel[i] = 0;//was -1
	}
	atom_table->size = size;
}
Exemplo n.º 16
0
/*
 * Resize the constant array or the int array of a sort to
 * accommodate a new constant or int.
 */
void sort_entry_resize(sort_entry_t *sort_entry) {
	if (sort_entry->size == sort_entry->cardinality) {
		if (MAXSIZE(sizeof(int32_t), 0) - sort_entry->size < sort_entry->size/2){
			out_of_memory();
		}
		sort_entry->size += sort_entry->size/2;
		if (sort_entry->constants != NULL) {
			sort_entry->constants = (int32_t *) safe_realloc(sort_entry->constants,
					sort_entry->size * sizeof(int32_t));
		}
		if (sort_entry->ints != NULL) {
			sort_entry->ints = (int32_t *) safe_realloc(sort_entry->ints,
					sort_entry->size * sizeof(int32_t));
		}
	}
}
Exemplo n.º 17
0
void init_sort_table(sort_table_t *sort_table){
	int32_t size = INIT_SORT_TABLE_SIZE;
	if (size >= MAXSIZE(sizeof(sort_entry_t), 0)){
		out_of_memory();
	}
	sort_table->size = size;
	sort_table->num_sorts = 0;
	sort_table->entries = (sort_entry_t*)safe_malloc(
			size*sizeof(sort_entry_t));
	/* this is not really needed */
	//for (i=0; i<size; i++){
	//	sort_table->entries[i].cardinality = 0;
	//	sort_table->entries[i].name = NULL;
	//}
	init_stbl(&(sort_table->sort_name_index), 0);
}
Exemplo n.º 18
0
void init_rule_inst_table(rule_inst_table_t *table){
	table->size = INIT_RULE_INST_TABLE_SIZE;
	table->num_rule_insts = 0;
	if (table->size >= MAXSIZE(sizeof(rule_inst_t *), 0)){
		out_of_memory();
	}
	table->rule_insts = (rule_inst_t **) safe_malloc(table->size * sizeof(rule_inst_t *));
	table->assignment = (samp_truth_value_t *) safe_malloc(
			table->size * sizeof(samp_truth_value_t));
	table->watched = (samp_clause_list_t *) safe_malloc(
			2 * INIT_ATOM_TABLE_SIZE * sizeof(samp_clause_list_t));
	table->rule_watched = (samp_clause_list_t *) safe_malloc(
			table->size * sizeof(samp_clause_list_t));
	init_clause_list(&table->sat_clauses);
	init_clause_list(&table->unsat_clauses);
	init_clause_list(&table->live_clauses);
	init_hmap(&table->unsat_soft_rules, HMAP_DEFAULT_SIZE);
}
Exemplo n.º 19
0
Arquivo: parser.c Projeto: SRI-CSL/pce
static void input_stack_resize() {
  int32_t capacity, newcap, size;
  if (parse_input_stack.input == NULL) {
    parse_input_stack.input = (parse_input_t **)
      safe_malloc(INIT_INPUT_STACK_SIZE * sizeof(parse_input_t *));
    parse_input_stack.capacity = INIT_INPUT_STACK_SIZE;
  }
  capacity = parse_input_stack.capacity;
  size = parse_input_stack.size;
  if (capacity < size + 1) {
    newcap = capacity + capacity/2;
    if (MAXSIZE(sizeof(parse_input_t *), 0) - capacity <= capacity/2) {
      out_of_memory();
    }
    parse_input_stack.input = (parse_input_t **)
      safe_realloc(parse_input_stack.input, newcap * sizeof(parse_input_t *));
    parse_input_stack.capacity = newcap;
  }
}
Exemplo n.º 20
0
/* Prepares for adding a rule for a pred entry */
void pred_rule_table_resize(pred_entry_t *pred_entry) {
	int32_t size;
	if (pred_entry->num_rules >= pred_entry->size_rules) {
		if (pred_entry->size_rules == 0) {
			pred_entry->rules = (int32_t *) safe_malloc(
					INIT_RULE_PRED_SIZE * sizeof(int32_t));
			pred_entry->size_rules = INIT_RULE_PRED_SIZE;
		} else {
			size = pred_entry->size_rules;
			if (MAXSIZE(sizeof(int32_t), 0) - size <= size / 2) {
				out_of_memory();
			}
			size += size / 2;
			pred_entry->rules = (int32_t *) safe_realloc(pred_entry->rules,
					size * sizeof(int32_t));
			pred_entry->size_rules = size;
		}
	}
}
Exemplo n.º 21
0
/*
 * Check whether there's room for one more clause in rule_inst_table.
 * - if not, make the table larger
 */
void rule_inst_table_resize(rule_inst_table_t *rule_inst_table){
	int32_t size = rule_inst_table->size;
	int32_t num_rinsts = rule_inst_table->num_rule_insts;
	if (num_rinsts + 1 < size) return;
	if (MAXSIZE(sizeof(rule_inst_t *), 0) - size <= (size/2)){
		out_of_memory();
	}
	size += size/2;
	rule_inst_table->rule_insts = (rule_inst_t **) safe_realloc(
			rule_inst_table->rule_insts, size * sizeof(rule_inst_t *));
	rule_inst_table->assignment = (samp_truth_value_t *) safe_realloc(
			rule_inst_table->assignment, size * sizeof(samp_truth_value_t));
	rule_inst_table->rule_watched = (samp_clause_list_t *) safe_realloc(
			rule_inst_table->rule_watched, size * sizeof(samp_clause_list_t));
	rule_inst_table->size = size; 
	//if (MAXSIZE(sizeof(samp_clause_t *), sizeof(rule_inst_t)) < num_clauses) {
	//	out_of_memory();
	//}
}
Exemplo n.º 22
0
void MoveFromDemoBuffer(source_t *who, int frame, int size)
{
	who->frames[frame&UPDATE_MASK].buf.data += size;
	who->frames[frame&UPDATE_MASK].buf.bufsize -= size;
	who->frames[frame&UPDATE_MASK].buf.maxsize -= size;

	who->dbuffer.start += size;
	if (who->dbuffer.start == who->dbuffer.last)
	{

		if (who->dbuffer.start == who->dbuffer.end)
		{
			who->dbuffer.end = 0; // demobuffer is empty
			who->dbuffer.msgbuf->data = who->dbuffer.data;
			who->dbuffer.msgbuf->bufsize = 0;
		}

		// go back to begining of the buffer
		who->dbuffer.last = who->dbuffer.end;
		who->dbuffer.start = 0;
	}

	who->dbuffer.msgbuf->maxsize = MAXSIZE(&who->dbuffer) + who->dbuffer.msgbuf->bufsize;
}