Exemplo n.º 1
0
Arquivo: sets.c Projeto: jleffler/soq
static void test_ops(void)
{
    Set *s1 = set_create();
    Set *s2 = set_create();
    Set *s3 = set_create();

    if (s1 == 0 || s2 == 0 || s3  == 0)
        err_syserr("Out of memory\n");

    load_set(s1, 1, 3, 4, 6);
    dump_set("S1", s1);

    load_set(s2, 2, 5, 7, 9);
    dump_set("S2", s2);

    set_union(s1, s2, s3);
    dump_set("S1 union S2", s3);

    set_empty(s3);
    set_intersect(s1, s2, s3);
    dump_set("S1 intersect S2", s3);

    set_empty(s3);
    set_difference(s1, s2, s3);
    dump_set("S1 minus S2", s3);

    set_empty(s3);
    set_difference(s2, s1, s3);
    dump_set("S2 minus S1", s3);

    set_destroy(s1);
    set_destroy(s2);
    set_destroy(s3);
}
Exemplo n.º 2
0
static int
count_operand (operand_t *op)
{
	flowvar_t  *var;

	if (!op)
		return 0;
	if (op->op_type == op_label)
		return 0;

	var = flow_get_var (op);
	// flowvars are initialized with number == 0, and any global flowvar
	// used by a function will always have a number >= 0 after flow analysis,
	// and local flowvars will always be 0 before flow analysis, so use -1
	// to indicate the variable has been counted.
	//
	// Also, since this is the beginning of flow analysis for this function,
	// ensure the define/use sets for global vars are empty. However, as
	// checking if a var is global is too much trouble, just clear them all.
	if (var && var->number != -1) {
		set_empty (var->use);
		set_empty (var->define);
		var->number = -1;
		return 1;
	}
	return 0;
}
Exemplo n.º 3
0
IntervalMatrix& IntervalMatrix::operator&=(const IntervalMatrix& m) {
	assert(nb_rows()==m.nb_rows());
	assert(nb_cols()==m.nb_cols());

	if (is_empty()) return *this;
	if (m.is_empty()) { set_empty(); return *this; }

	for (int i=0; i<_nb_rows; i++) {
		if ((row(i) &= m.row(i)).is_empty()) { set_empty(); return *this; }
	}
	return *this;
}
Exemplo n.º 4
0
/* Virtual functions */
static void
e_reflow_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
	GnomeCanvasItem *item;
	EReflow *reflow;

	item = GNOME_CANVAS_ITEM (object);
	reflow = E_REFLOW (object);

	switch (prop_id){
	case PROP_HEIGHT:
		reflow->height = g_value_get_double (value);
		reflow->need_reflow_columns = TRUE;
		e_canvas_item_request_reflow(item);
		break;
	case PROP_MINIMUM_WIDTH:
		reflow->minimum_width = g_value_get_double (value);
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		e_canvas_item_request_reflow(item);
		break;
	case PROP_EMPTY_MESSAGE:
		g_free(reflow->empty_message);
		reflow->empty_message = g_strdup(g_value_get_string (value));
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		break;
	case PROP_MODEL:
		connect_model (reflow, (EReflowModel *) g_value_get_object (value));
		break;
	case PROP_COLUMN_WIDTH:
		if (reflow->column_width != g_value_get_double (value)) {
			GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
			double old_width = reflow->column_width;

			reflow->column_width = g_value_get_double (value);
			adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
			adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
			gtk_adjustment_changed(adjustment);
			e_reflow_resize_children(item);
			e_canvas_item_request_reflow(item);

			reflow->need_column_resize = TRUE;
			gnome_canvas_item_request_update(item);

			if (old_width != reflow->column_width)
				column_width_changed (reflow);
		}
		break;
	}
}
Exemplo n.º 5
0
static int	set_arena(t_corewar *corewar, unsigned char **arena)
{
  int		i;
  int		index;
  t_champion	*tmp;

  tmp = corewar->champions;
  if ((*arena = my_malloc(MEM_SIZE * sizeof(char))) == NULL)
    return (my_fprintf(2, "At set_arena : Malloc failed.\n"));
  set_empty(corewar, arena);
  i = 0;
  while (tmp)
    {
      index = tmp->address;
      tmp->pc = index;
      while ((tmp->code) && (i < tmp->size) && (index < MEM_SIZE))
	if ((*arena)[index] == 0)
	  (*arena)[(index++) % MEM_SIZE] = tmp->code[i++];
	else
	  return (my_fprintf(2, "In \"set_arena\", address conflict\n"));
      i = 0;
      tmp = tmp->next;
    }
  return (0);
}
Exemplo n.º 6
0
void SlotPreview::setMode(int mode)
{
	switch(mode)
	{
	   case 0: set_empty(); break;
	   case 1: set_psx_game();break;
	   case 2: set_ff7_save();break;
	}
}
Exemplo n.º 7
0
void msg_queue::clear()
{
	lock l(&m_mutex);
	m_queue.clear();
	while (m_queue.size()>0)
	{
		delete(m_queue.front());
		m_queue.pop_front();
	}
	set_empty();
}
Exemplo n.º 8
0
template<class T, class Policies> inline
interval<T, Policies>& interval<T, Policies>::operator-=(const T& r)
{
  if (interval_lib::detail::test_input(*this, r))
    set_empty();
  else {
    typename Policies::rounding rnd;
    set(rnd.sub_down(low, r), rnd.sub_up(up, r));
  }
  return *this;
}
Exemplo n.º 9
0
msg*  msg_queue::pop_front()
{
	lock l(&m_mutex);
	msg* tmp = front();
	//
	m_queue.pop_front();
	if (size() == 0 )
	{
		set_empty();
	}
	return tmp;
}
Exemplo n.º 10
0
static void
items_inserted (EReflowModel *model, int position, int count, EReflow *reflow)
{
	int i, oldcount;

	if (position < 0 || position > reflow->count)
		return;

	oldcount = reflow->count;

	reflow->count += count;

	if (reflow->count > reflow->allocated_count) {
		while (reflow->count > reflow->allocated_count)
			reflow->allocated_count += 256;
		reflow->heights = g_renew (int, reflow->heights, reflow->allocated_count);
		reflow->items = g_renew (GnomeCanvasItem *, reflow->items, reflow->allocated_count);
	}
	memmove (reflow->heights + position + count, reflow->heights + position, (reflow->count - position - count) * sizeof (int));
	memmove (reflow->items + position + count, reflow->items + position, (reflow->count - position - count) * sizeof (GnomeCanvasItem *));
	for (i = position; i < position + count; i++) {
		reflow->items[i] = NULL;
		reflow->heights[i] = e_reflow_model_height (reflow->model, i, GNOME_CANVAS_GROUP (reflow));
	}

	e_selection_model_simple_set_row_count (E_SELECTION_MODEL_SIMPLE (reflow->selection), reflow->count);
	if (position == oldcount)
		e_sorter_array_append (reflow->sorter, count);
	else
		e_sorter_array_set_count (reflow->sorter, reflow->count);

	for (i = position; i < position + count; i ++) {
		int sorted = e_sorter_model_to_sorted (E_SORTER (reflow->sorter), i);
		int c;

		for (c = reflow->column_count - 1; c >= 0; c--) {
			int start_of_column = reflow->columns[c];

			if (start_of_column <= sorted) {
				if (reflow->reflow_from_column == -1
				    || reflow->reflow_from_column > c) {
					reflow->reflow_from_column = c;
				}
				break;
			}
		}
	}

	reflow->need_reflow_columns = TRUE;
	set_empty (reflow);
	e_canvas_item_request_reflow(GNOME_CANVAS_ITEM (reflow));
}
Exemplo n.º 11
0
static void set_object(void* S)
{
  fprintf(stdout, 
      "\t__set__ -> {\n"
      "\t  object=>0x%p,\n"
      "\t  size=>%d,\n"
      "\t  empty=>'%s',\n"
      "\t  begin=>0x%p,\n"
      "\t  end=>0x%p,\n"
      "\t}\n", 
      S, set_size(S), (set_empty(S) ? "yes" : "no"), 
      set_begin(S), set_end(S)
      );
}
Exemplo n.º 12
0
static void
e_reflow_realize (GnomeCanvasItem *item)
{
	EReflow *reflow;
	GtkAdjustment *adjustment;
	int count;
	int i;

	reflow = E_REFLOW (item);

	if (GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->realize)
		(* GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->realize) (item);

	reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
	reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR);

	count = reflow->count;
	for(i = 0; i < count; i++) {
		if (reflow->items[i])
			gnome_canvas_item_set(reflow->items[i],
					      "width", reflow->column_width,
					      NULL);
	}

	set_empty(reflow);

	reflow->need_reflow_columns = TRUE;
	e_canvas_item_request_reflow(item);

	adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));

#if 0
	connect_set_adjustment (reflow);
#endif
	connect_adjustment (reflow, adjustment);

	adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
	adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
	gtk_adjustment_changed(adjustment);

	if (!item->canvas->aa) {
	}
}
Exemplo n.º 13
0
static void
flow_find_dominators (flowgraph_t *graph)
{
	set_t      *work;
	flownode_t *node;
	int         i;
	set_iter_t *pred;
	int         changed;

	if (!graph->num_nodes)
		return;

	// First, create a base set for the initial state of the non-initial nodes
	work = set_new ();
	for (i = 0; i < graph->num_nodes; i++)
		set_add (work, i);

	set_add (graph->nodes[0]->dom, 0);

	// initialize dom for the non-initial nodes
	for (i = 1; i < graph->num_nodes; i++) {
		set_assign (graph->nodes[i]->dom, work);
	}

	do {
		changed = 0;
		for (i = 1; i < graph->num_nodes; i++) {
			node = graph->nodes[i];
			pred = set_first (node->predecessors);
			set_empty (work);
			for (pred = set_first (node->predecessors); pred;
				 pred = set_next (pred))
				set_intersection (work, graph->nodes[pred->element]->dom);
			set_add (work, i);
			if (!set_is_equivalent (work, node->dom))
				changed = 1;
			set_assign (node->dom, work);
		}
	} while (changed);
	set_delete (work);
}
Exemplo n.º 14
0
static void
item_removed (EReflowModel *model, int i, EReflow *reflow)
{
	int c;
	int sorted;

	if (i < 0 || i >= reflow->count)
		return;

	sorted = e_sorter_model_to_sorted (E_SORTER (reflow->sorter), i);
	for (c = reflow->column_count - 1; c >= 0; c--) {
		int start_of_column = reflow->columns[c];

		if (start_of_column <= sorted) {
			if (reflow->reflow_from_column == -1
			    || reflow->reflow_from_column > c) {
				reflow->reflow_from_column = c;
			}
			break;
		}
	}

	if (reflow->items[i])
		gtk_object_destroy (GTK_OBJECT (reflow->items[i]));

	memmove (reflow->heights + i, reflow->heights + i + 1, (reflow->count - i - 1) * sizeof (int));
	memmove (reflow->items + i, reflow->items + i + 1, (reflow->count - i - 1) * sizeof (GnomeCanvasItem *));

	reflow->count --;

	reflow->heights [reflow->count] = 0;
	reflow->items [reflow->count] = NULL;

	reflow->need_reflow_columns = TRUE;
	set_empty (reflow);
	e_canvas_item_request_reflow(GNOME_CANVAS_ITEM (reflow));

	e_sorter_array_set_count (reflow->sorter, reflow->count);

	e_selection_model_simple_delete_rows (E_SELECTION_MODEL_SIMPLE (reflow->selection), i, 1);
}
Exemplo n.º 15
0
static void
model_changed (EReflowModel *model, EReflow *reflow)
{
	int i;
	int count;
	int oldcount;

	count = reflow->count;
	oldcount = count;

	for (i = 0; i < count; i++) {
		if (reflow->items[i])
			gtk_object_destroy (GTK_OBJECT (reflow->items[i]));
	}
	g_free (reflow->items);
	g_free (reflow->heights);
	reflow->count = e_reflow_model_count (model);
	reflow->allocated_count = reflow->count;
	reflow->items = g_new (GnomeCanvasItem *, reflow->count);
	reflow->heights = g_new (int, reflow->count);

	count = reflow->count;
	for (i = 0; i < count; i++) {
		reflow->items[i] = NULL;
		reflow->heights[i] = e_reflow_model_height (reflow->model, i, GNOME_CANVAS_GROUP (reflow));
	}

	e_selection_model_simple_set_row_count (E_SELECTION_MODEL_SIMPLE (reflow->selection), count);
	e_sorter_array_set_count (reflow->sorter, reflow->count);

	reflow->need_reflow_columns = TRUE;
	if (oldcount > reflow->count)
		reflow_columns (reflow);
	set_empty (reflow);
	e_canvas_item_request_reflow(GNOME_CANVAS_ITEM (reflow));
}
Exemplo n.º 16
0
static void
flow_uninitialized (flowgraph_t *graph)
{
	int         i;
	flownode_t *node;
	flowvar_t  *var;
	set_iter_t *var_i;
	set_t      *defs;
	set_t      *uninitialized;

	uninitialized = set_new ();
	node = graph->nodes[graph->num_nodes];
	set_assign (uninitialized, node->reaching_defs.out);
	defs = set_new ();

	for (i = 0; i < graph->num_nodes; i++) {
		node = graph->nodes[graph->dfo[i]];
		set_empty (defs);
		// collect definitions of all variables "used" in this node. use from
		// the live vars analysis is perfect for the job
		for (var_i = set_first (node->live_vars.use); var_i;
			 var_i = set_next (var_i)) {
			var = graph->func->vars[var_i->element];
			set_union (defs, var->define);
		}
		// interested in only those defintions that actually reach this node
		set_intersection (defs, node->reaching_defs.in);
		// if any of the definitions come from the entry dummy block, then
		// the statements need to be scanned in case an aliasing definition
		// kills the dummy definition before the usage, and also so the line
		// number information can be obtained from the statement.
		if (set_is_intersecting (defs, uninitialized))
			flow_uninit_scan_statements (node, defs, uninitialized);
	}
	set_delete (defs);
}
Exemplo n.º 17
0
void generator_t::reset()
{
    digest_.reset();
    ss_.str( std::string());
    set_empty( true);
}
Exemplo n.º 18
0
generator_t::generator_t() {
    set_empty( true);
}
Exemplo n.º 19
0
static void
flow_find_successors (flowgraph_t *graph)
{
	int         i;
	flownode_t *node;
	sblock_t   *sb;
	statement_t *st;
	sblock_t  **target_list, **target;

	// "convert" the basic blocks connections to flow-graph connections
	for (i = 0; i < graph->num_nodes + 2; i++) {
		node = graph->nodes[i];
		set_empty (node->successors);
		set_empty (node->predecessors);
		set_empty (node->edges);
	}
	graph->num_edges = 0;

	for (i = 0; i < graph->num_nodes; i++) {
		node = graph->nodes[i];
		sb = node->sblock;
		st = 0;
		if (sb->statements)
			st = (statement_t *) sb->tail;
		//NOTE: if st is null (the sblock has no statements), statement_is_*
		//will return false
		//FIXME jump/jumpb
		if (statement_is_goto (st) || statement_is_jumpb (st)) {
			// sb's next is never followed.
			target_list = statement_get_targetlist (st);
			for (target = target_list; *target; target++)
				set_add (node->successors, (*target)->flownode->id);
			free (target_list);
		} else if (statement_is_cond (st)) {
			// branch: either sb's next or the conditional statment's
			// target will be followed.
			set_add (node->successors, sb->next->flownode->id);
			target_list = statement_get_targetlist (st);
			for (target = target_list; *target; target++)
				set_add (node->successors, (*target)->flownode->id);
			free (target_list);
		} else if (statement_is_return (st)) {
			// exit from function (dead end)
			// however, make the exit dummy block the node's successor
			set_add (node->successors, graph->num_nodes + 1);
		} else {
			// there is no flow-control statement in sb, so sb's next
			// must be followed
			if (sb->next) {
				set_add (node->successors, sb->next->flownode->id);
			} else {
				bug (0, "code drops off the end of the function");
				// this shouldn't happen
				// however, make the exit dummy block the node's successor
				set_add (node->successors, graph->num_nodes + 1);
			}
		}
		graph->num_edges += set_size (node->successors);
	}
	// set the successor for the entry dummy node to the real entry node
	node = graph->nodes[graph->num_nodes];
	set_add (node->successors, 0);
	graph->num_edges += set_size (node->successors);
}
Exemplo n.º 20
0
/*
 * unweighted_clique_search_single()
 *
 * Searches for a single clique of size min_size.  Stores maximum clique
 * sizes into clique_size[].
 *
 *   table    - the order of the vertices in g to use
 *   min_size - minimum size of clique to search for.  If min_size==0,
 *              searches for a maximum clique.
 *   g        - the graph
 *   opts     - time printing options
 *
 * opts->time_function is called after each base-level recursion, if
 * non-NULL.
 *
 * Returns the size of the clique found, or 0 if min_size>0 and a clique
 * of that size was not found (or if time_function aborted the search).
 * The largest clique found is stored in current_clique.
 *
 * Note: Does NOT use opts->user_function of opts->clique_list.
 */
static int unweighted_clique_search_single(int *table, int min_size,
					   graph_t *g, clique_options *opts) {
	struct tms tms;
	struct timeval timeval;
	int i,j;
	int v,w;
	int *newtable;
	int newsize;

	v=table[0];
	clique_size[v]=1;
	set_empty(current_clique);
	SET_ADD_ELEMENT(current_clique,v);
	if (min_size==1)
		return 1;

	if (temp_count) {
		temp_count--;
		newtable=temp_list[temp_count];
	} else {
		newtable=malloc(g->n * sizeof(int));
	}
	for (i=1; i < g->n; i++) {
		w=v;
		v=table[i];

		newsize=0;
		for (j=0; j<i; j++) {
			if (GRAPH_IS_EDGE(g, v, table[j])) {
				newtable[newsize]=table[j];
				newsize++;
			}
		}

		if (sub_unweighted_single(newtable,newsize,clique_size[w],g)) {
			SET_ADD_ELEMENT(current_clique,v);
			clique_size[v]=clique_size[w]+1;
		} else {
			clique_size[v]=clique_size[w];
		}

		if (opts && opts->time_function) {
			gettimeofday(&timeval,NULL);
			times(&tms);
			if (!opts->time_function(entrance_level,
						 i+1,g->n,clique_size[v] *
						 weight_multiplier,
						 (double)(tms.tms_utime-
							  cputimer.tms_utime)/
						 clocks_per_sec,
						 timeval.tv_sec-
						 realtimer.tv_sec+
						 (double)(timeval.tv_usec-
							  realtimer.tv_usec)/
						 1000000,opts)) {
				temp_list[temp_count++]=newtable;
				return 0;
			}
		}

		if (min_size) {
			if (clique_size[v]>=min_size) {
				temp_list[temp_count++]=newtable;
				return clique_size[v];
			}
			if (clique_size[v]+g->n-i-1 < min_size) {
				temp_list[temp_count++]=newtable;
				return 0;
			}
		}
	}

	temp_list[temp_count++]=newtable;

	if (min_size)
		return 0;
	return clique_size[v];
}
Exemplo n.º 21
0
/*************************************************************************
 *
 *N  get_selected_primitives
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function determines all of the selected primitive rows from
 *    the selected features.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <input> == (view_type *) view structure.
 *     themenum <input> == (int) theme number.
 *     library  <input> == (library_type *) VPF library structure.
 *     mapenv   <input> == (map_environment_type *) map environment.
 *     status  <output> == (int *) status of the function:
 *                         1 if completed, 0 if user escape.
 *     get_selected_primitives <output> == (set_type *) array of sets, each position
 *                         representing the set of primitives for the
 *                         corresponding tile in the tileref.aft table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
set_type *get_selected_primitives( view_type *view,
				   int themenum,
				   library_type *library,
				   map_environment_type *mapenv,
				   int *status )
{
   int fcnum, finished, found, cov, tilecover, TILEPATH_, degree;
   int feature, prim;
   vpf_table_type tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   char *spxname[] = {"","esi","fsi","tsi","nsi","csi"};
   char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"};
   set_type feature_rows, primitive_rows, tile_features;
   set_type *primitives;
   rspf_int32 prim_rownum, count, tile;
   register rspf_int32 i,j, pclass, start,end;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   fcrel_type fcrel;
   linked_list_type primlist;
   position_type p;
   vpf_relate_struct rcell;
   ThematicIndex idx;

   primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type));
   for (i=0;i<=library->ntiles;i++) {
      primitives[i].size = 0;
      primitives[i].buf = NULL;
   }

   fcnum = view->theme[themenum].fcnum;

   feature_rows = get_selected_features( view, themenum, *library );

   /* Open the tile reference table, if present */
   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) {

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      feature = 0;
      prim = fcrel.nchain-1;

      p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list);
      ll_element(p,&rcell);
      degree = rcell.degree;

      /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/
      for (tile = 2; tile <= library->ntiles; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = 1;
	 found = 0;

	 /* Open primitive table in tile */
	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);
	 if (access(path,0) != 0) continue;
	 found = 1;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 if (primitives[tile].size > 0) {
	    printf("Oops!  size = %ld\n",primitives[tile].size);
	    exit(1);
	 }
	 primitives[tile] = set_init(fcrel.table[prim].nrows+1);

	 /* Get the set of primitive rows within the map extent */

	 /* Look for spatial index file */
	 primitive_rows.size = 0;
	 if (mapenv->projection == PLATE_CARREE &&
	     mapenv->mapextent.x1 < mapenv->mapextent.x2) {
	    sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]);
	    if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) {

	       primitive_rows = spatial_index_search(path,
			  mapenv->mapextent.x1,mapenv->mapextent.y1,
			  mapenv->mapextent.x2,mapenv->mapextent.y2);

	    } else {
	       /* Next best thing - bounding rectangle table */
	       sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]);
	       if (access(path,0)==0) {
		  primitive_rows = bounding_select(path,mapenv->mapextent,
						   library->dec_degrees);
	       }
	    }
	 } /* projection check */

	 if (primitive_rows.size == 0) {
	    /* Search through all the primitives */
	    primitive_rows=set_init(fcrel.table[prim].nrows+1);
	    set_on(primitive_rows);
	 }

	 tile_thematic_index_name(fcrel.table[feature], path);
	 if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) {
	    /* Tile thematic index for feature table present, */
	    tile_features = read_thematic_index( path, (char *)&tile );
	 } else {
	    tile_features = set_init(fcrel.table[feature].nrows+1);
	    set_on(tile_features);
	 }

	 idx.fp = NULL;
	 i = table_pos(rcell.key2,fcrel.table[prim]);
	 if (i >= 0) {
	    if (fcrel.table[prim].header[i].tdx) {
	       sprintf(path,"%s%s",fcrel.table[prim].path,
				fcrel.table[prim].header[i].tdx);
	       if (access(path,0)==0)
		  idx = open_thematic_index(path);
	    }
	    if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE;
	    if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY;
	    if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE;
	 }

	 finished = 1;

	 start = set_min(tile_features);
	 end = set_max(tile_features);

	 fseek(fcrel.table[feature].fp,
	       index_pos(start,fcrel.table[feature]),
	       SEEK_SET);

	 for (i=start;i<=end;i++) {

	    row = read_next_row(fcrel.table[feature]);

	    if (!set_member( i, feature_rows )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (!set_member( i, tile_features )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (degree == R_ONE) {
	       prim_rownum = fc_row_number( row, fcrel, tile );
	       primlist = NULL;
	       p = NULL;
	    } else {
	       primlist = fc_row_numbers( row, fcrel, tile, &idx );
	    }

	    free_row( row, fcrel.table[feature] );

	    if (!primlist) {
	       if ((prim_rownum<1)||
		   (prim_rownum>fcrel.table[prim].nrows))
		  continue;
	       if (set_member( prim_rownum, primitive_rows )) {
		  set_insert(prim_rownum,primitives[tile]);
	       }
	    } else {
	       p = ll_first(primlist);
	       while (!ll_end(p)) {
		  ll_element(p,&prim_rownum);
		  if ((prim_rownum<1)||
		      (prim_rownum>fcrel.table[prim].nrows))
		     continue;
		  if (set_member( prim_rownum, primitive_rows )) {
		     set_insert(prim_rownum,primitives[tile]);
		  }
		  p = ll_next(p);
	       }
	    }

	    if (kbhit()) {
	       if (getch()==27) {
		  *status = 0;
		  finished = 0;
		  break;
	       }
	    }
	 }

	 if (idx.fp) close_thematic_index(&idx);

	 vpf_close_table(&(fcrel.table[prim]));

	 set_nuke(&primitive_rows);

	 set_nuke(&tile_features);

	 if (set_empty(primitives[tile])) {
	    set_nuke(&primitives[tile]);
	    primitives[tile].size = 0;
	    primitives[tile].buf = NULL;
	 }

	 if (!finished) {
	    *status = 0;
	    break;
	 }

      }

      if (!finished) {
	 *status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      if (found) *status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    *status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate( &fcrel );
   }

   set_nuke(&feature_rows);

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   return primitives;
}
Exemplo n.º 22
0
int main()
{
	struct timeval start, end;
    int running = 1;
    void *shared_memory = (void *)0;
    struct shared_use_st *shared_stuff;
    int shmid;

    srand((unsigned int)getpid());

    sem_id = semget((key_t)1233, 1, 0666 | IPC_CREAT);
    sem_id2 = semget((key_t)1235, 1, 0666 | IPC_CREAT);
    sem_id3 = semget((key_t)1236, 1, 0666 | IPC_CREAT);
    
	if (!set_available()| !set_empty()) {
            fprintf(stderr, "Failed to initialize semaphore\n");
            exit(EXIT_FAILURE);
        }

    shmid = shmget((key_t)1231, (sizeof(struct shared_use_st)- sizeof(int)) , 0666 | IPC_CREAT);

    if (shmid == -1) {
        fprintf(stderr, "shmget failed prod\n");
        exit(EXIT_FAILURE);
    }

/* We now make the shared memory accessible to the program. */

    shared_memory = shmat(shmid, (void *)0, 0);
    if (shared_memory == (void *)-1) {
        fprintf(stderr, "shmat failed\n");
        exit(EXIT_FAILURE);
    }

    printf("Memory attached at %X\n", (void *)shared_memory);

/* The next portion of the program assigns the shared_memory segment to shared_stuff,
 which then prints out any text in written_by_you. The loop continues until end is found
 in written_by_you. The call to sleep forces the consumer to sit in its critical section,
 which makes the producer wait. */

    shared_stuff = (struct shared_use_st *)shared_memory;
    //shared_stuff->written_by_you = 0;

    char ibuffer[BUFSIZ];   // input buffer 
 
    int in; // variable to hold reference to input file
    int index=0; // current index of element in array of structs in shared memory 
    int len;  // length read 
     int tot = 0; // Total length read

	//timer start
	gettimeofday(&start, NULL);
	for (int i = 0; i < 100000; i++){}
	
    in = open("test4k.txt",O_RDONLY);
   
	len = read(in,ibuffer, sizeof(ibuffer));
    while(running){
	
	for(int i = 0; i<= len; i+=128){
		//sleep(2);
		if((len-i)<128){
		
		shared_stuff->msgs[index].written = len-i;
		memcpy(shared_stuff->msgs[index].some_text, ibuffer + (len-i), (len-i));
		tot+= shared_stuff->msgs[index].written;
		printf("Producer: bytes written val %d\n", shared_stuff->msgs[index].written);

		printf("Producer: Total bytes written val %d\n", tot);		

		
		//timer finished
		gettimeofday(&end, NULL);
		printf("\nElapsed Time: %ld micro sec\n", ((end.tv_sec * MICRO_SEC_IN_SEC + end.tv_usec)- (start.tv_sec * MICRO_SEC_IN_SEC + start.tv_usec)));
		
		sleep(4);
		del_semvalue();
		
		/*
		//timer finished
		gettimeofday(&end, NULL);
		printf("\nElapsed Time: %ld micro sec\n", ((end.tv_sec * MICRO_SEC_IN_SEC + end.tv_usec)- (start.tv_sec * MICRO_SEC_IN_SEC + start.tv_usec)));
		*/
		exit(EXIT_SUCCESS);
		
		}
		else{
		empty_p();	
		
 		shared_stuff->msgs[index].written = 128;
		//printf("writte\n");
		printf("Producer: bytes written val %d\n", shared_stuff->msgs[index].written);
		memcpy(shared_stuff->msgs[index].some_text,ibuffer + i,128);		
		tot+= shared_stuff->msgs[index].written;
		
		index = (index+1)%k;  

		available_v();
		
		}
	}
   }
  

/* Lastly, the shared memory is detached and then deleted. */

    if (shmdt(shared_memory) == -1) {
        fprintf(stderr, "shmdt failed\n");
        exit(EXIT_FAILURE);
    }

    if (shmctl(shmid, IPC_RMID, 0) == -1) {
        fprintf(stderr, "shmctl(IPC_RMID) failed\n");
        exit(EXIT_FAILURE);
    }

	//del_semvalue();

    exit(EXIT_SUCCESS);
}
Exemplo n.º 23
0
/*
 * weighted_clique_search_single()
 *
 * Searches for a single clique of weight at least min_weight, and at
 * most max_weight.  Stores maximum clique sizes into clique_size[]
 * (or min_weight-1, whichever is smaller).
 *
 *   table      - the order of the vertices in g to use
 *   min_weight - minimum weight of clique to search for.  If min_weight==0,
 *                then searches for a maximum weight clique
 *   max_weight - maximum weight of clique to search for.  If no upper limit
 *                is desired, use eg. INT_MAX
 *   g          - the graph
 *   opts       - time printing options
 *
 * opts->time_function is called after each base-level recursion, if
 * non-NULL.
 *
 * Returns 0 if a clique of requested weight was not found (also if
 * time_function requested an abort), otherwise returns >= 1.
 * If min_weight==0 (search for maximum-weight clique), then the return
 * value is the weight of the clique found.  The found clique is stored
 * in best_clique.
 *
 * Note: Does NOT use opts->user_function of opts->clique_list.
 */
static int weighted_clique_search_single(int *table, int min_weight,
					 int max_weight, graph_t *g,
					 clique_options *opts) {
	struct timeval timeval;
	struct tms tms;
	int i,j;
	int v;
	int *newtable;
	int newsize;
	int newweight;
	int search_weight;
	int min_w;
	clique_options localopts;

	if (min_weight==0)
		min_w=INT_MAX;
	else
		min_w=min_weight;


	if (min_weight==1) {
		/* min_weight==1 may cause trouble in the routine, and
		 * it's trivial to check as it's own case.
		 * We write nothing to clique_size[]. */
		for (i=0; i < g->n; i++) {
			if (g->weights[table[i]] <= max_weight) {
				set_empty(best_clique);
				SET_ADD_ELEMENT(best_clique,table[i]);
				return g->weights[table[i]];
			}
		}
		return 0;
	}
	
	localopts.time_function=NULL;
	localopts.reorder_function=NULL;
	localopts.reorder_map=NULL;
	localopts.user_function=false_function;
	localopts.user_data=NULL;
	localopts.clique_list=&best_clique;
	localopts.clique_list_length=1;
	clique_list_count=0;

	v=table[0];
	set_empty(best_clique);
	SET_ADD_ELEMENT(best_clique,v);
	search_weight=g->weights[v];
	if (min_weight && (search_weight >= min_weight)) {
		if (search_weight <= max_weight) {
			/* Found suitable clique. */
			return search_weight;
		}
		search_weight=min_weight-1;
	}
	clique_size[v]=search_weight;
	set_empty(current_clique);

	if (temp_count) {
		temp_count--;
		newtable=temp_list[temp_count];
	} else {
		newtable=malloc(g->n * sizeof(int));
	}

	for (i = 1; i < g->n; i++) {
		v=table[i];

		newsize=0;
		newweight=0;
		for (j=0; j<i; j++) {
			if (GRAPH_IS_EDGE(g,v,table[j])) {
				newweight += g->weights[table[j]];
				newtable[newsize]=table[j];
				newsize++;
			}
		}


		SET_ADD_ELEMENT(current_clique,v);
		search_weight=sub_weighted_all(newtable,newsize,newweight,
					       g->weights[v],search_weight,
					       clique_size[table[i-1]] +
					       g->weights[v],
					       min_w,max_weight,FALSE,
					       g,&localopts);
		SET_DEL_ELEMENT(current_clique,v);
		if (search_weight < 0) {
			break;
		}

		clique_size[v]=search_weight;

		if (opts->time_function) {
			gettimeofday(&timeval,NULL);
			times(&tms);
			if (!opts->time_function(entrance_level,
						 i+1,g->n,clique_size[v] *
						 weight_multiplier,
						 (double)(tms.tms_utime-
							  cputimer.tms_utime)/
						 clocks_per_sec,
						 timeval.tv_sec-
						 realtimer.tv_sec+
						 (double)(timeval.tv_usec-
							  realtimer.tv_usec)/
						 1000000,opts)) {
				set_free(current_clique);
				current_clique=NULL;
				break;
			}
		}
	}
	temp_list[temp_count++]=newtable;
	if (min_weight && (search_weight > 0)) {
		/* Requested clique has not been found. */
		return 0;
	}
	return clique_size[table[i-1]];
}
Exemplo n.º 24
0
int main()
{
    int running = 1;
    void *shared_memory = (void *)0;
    struct shared_use_st *shared_stuff;
    int shmid;

    srand((unsigned int)getpid());

	//get the semaphores	

    sem_id = semget((key_t)1233, 1, 0666 | IPC_CREAT);
    sem_id2 = semget((key_t)1235, 1, 0666 | IPC_CREAT);
    sem_id3 = semget((key_t)1236, 1, 0666 | IPC_CREAT);

/*
*sets the semaphores to the required values if it fails program ends
*/
    
	if (!set_mutex()| !set_available()| !set_empty()) {
            fprintf(stderr, "Failed to initialize semaphore\n");
            exit(EXIT_FAILURE);
        }

	//get shared memory

    shmid = shmget((key_t)1231, (sizeof(struct shared_use_st)- sizeof(int)) , 0666 | IPC_CREAT);

    if (shmid == -1) {
        fprintf(stderr, "shmget failed prod\n");
        exit(EXIT_FAILURE);
    }

/* We now make the shared memory accessible to the program. */

    shared_memory = shmat(shmid, (void *)0, 0);
    if (shared_memory == (void *)-1) {
        fprintf(stderr, "shmat failed\n");
        exit(EXIT_FAILURE);
    }

    printf("Memory attached at %X\n", (void *)shared_memory);

/* The next portion of the program assigns the shared_memory segment to shared_stuff,
 Reads in from the input file test4k.txt into the buffer ibuffer string of size BUFSIZ, then the 
 loop continually copies text from ibuffer into the buffers in shared memory which take 128 bytes of char until a value less than 128 is written which means approached end of text then it sleeps and deletes the semaphores */

    shared_stuff = (struct shared_use_st *)shared_memory;
    //shared_stuff->written_by_you = 0;

    char ibuffer[BUFSIZ];   // input buffer 
 
    int in; // variable to hold reference to input file
    int index=0; // current index of element in array of structs in shared memory 
    int len;  // length read 
     int tot = 0; // Total length read

    in = open("test4k.txt",O_RDONLY);
   
	len = read(in,ibuffer, sizeof(ibuffer));
    while(running){
	
	for(int i = 0; i<= len; i+=128){
		sleep(2);
		if((len-i)<128){

		//if value written is less than 128  delete semaphores


		shared_stuff->msgs[index].written = len-i;
		memcpy(shared_stuff->msgs[index].some_text, ibuffer + (len-i), (len-i));
		tot+= shared_stuff->msgs[index].written;
		printf("Producer: bytes written val %d\n", shared_stuff->msgs[index].written);

		printf("Producer: Total bytes written val %d\n", tot);		

		sleep(10);
		del_semvalue();
		exit(EXIT_SUCCESS);
		
		}
		else{
		empty_p();	
		mutex_p();

 		shared_stuff->msgs[index].written = 128;
		
		printf("Producer: bytes written val %d\n", shared_stuff->msgs[index].written);
		memcpy(shared_stuff->msgs[index].some_text,ibuffer + i,128);		
		tot+= shared_stuff->msgs[index].written;
		
		index = (index+1)%k;  
		mutex_v();
		available_v();
		
		}
	}
   }
  

/* Lastly, the shared memory is detached and then deleted. */

    if (shmdt(shared_memory) == -1) {
        fprintf(stderr, "shmdt failed\n");
        exit(EXIT_FAILURE);
    }

    if (shmctl(shmid, IPC_RMID, 0) == -1) {
        fprintf(stderr, "shmctl(IPC_RMID) failed\n");
        exit(EXIT_FAILURE);
    }

	

    exit(EXIT_SUCCESS);
}
Exemplo n.º 25
0
/*
 * weighted_clique_search_all()
 *
 * Searches for all cliques with weight at least min_weight and at most
 * max_weight.  Stores the cliques as opts declares.
 *
 *   table      - the order of the vertices in g to search
 *   start      - first index where the subgraph table[0], ..., table[start]
 *                might include a requested kind of clique
 *   min_weight - minimum weight of clique to search for.  min_weight > 0 !
 *   max_weight - maximum weight of clique to search for.  If no upper limit
 *                is desired, use eg. INT_MAX
 *   maximal    - search only for maximal cliques
 *   g          - the graph
 *   opts       - time printing and clique storage options
 *
 * Cliques found are stored as defined by opts->user_function and
 * opts->clique_list.  opts->time_function is called after each
 * base-level recursion, if non-NULL.
 *
 * clique_size[] must be defined and correct for all values of
 * table[0], ..., table[start-1].
 *
 * Returns the number of cliques stored (not neccessarily number of cliques
 * in graph, if user/time_function aborts).
 */
static int weighted_clique_search_all(int *table, int start,
				      int min_weight, int max_weight,
				      boolean maximal, graph_t *g,
				      clique_options *opts) {
	struct timeval timeval;
	struct tms tms;
	int i,j;
	int v;
	int *newtable;
	int newsize;
	int newweight;

	if (temp_count) {
		temp_count--;
		newtable=temp_list[temp_count];
	} else {
		newtable=malloc(g->n * sizeof(int));
	}

	clique_list_count=0;
	set_empty(current_clique);
	for (i=start; i < g->n; i++) {
		v=table[i];
		clique_size[v]=min_weight;   /* Do not prune here. */

		newsize=0;
		newweight=0;
		for (j=0; j<i; j++) {
			if (GRAPH_IS_EDGE(g,v,table[j])) {
				newtable[newsize]=table[j];
				newweight+=g->weights[table[j]];
				newsize++;
			}
		}

		SET_ADD_ELEMENT(current_clique,v);
		j=sub_weighted_all(newtable,newsize,newweight,
				   g->weights[v],min_weight-1,INT_MAX,
				   min_weight,max_weight,maximal,g,opts);
		SET_DEL_ELEMENT(current_clique,v);

		if (j<0) {
			/* Abort. */
			break;
		}

		if (opts->time_function) {
			gettimeofday(&timeval,NULL);
			times(&tms);
			if (!opts->time_function(entrance_level,
						 i+1,g->n,clique_size[v] *
						 weight_multiplier,
						 (double)(tms.tms_utime-
							  cputimer.tms_utime)/
						 clocks_per_sec,
						 timeval.tv_sec-
						 realtimer.tv_sec+
						 (double)(timeval.tv_usec-
							  realtimer.tv_usec)/
						 1000000,opts)) {
				set_free(current_clique);
				current_clique=NULL;
				break;
			}
		}
	}
	temp_list[temp_count++]=newtable;

	return clique_list_count;
}
Exemplo n.º 26
0
#include "dryad_sls.h"

_(dryad)
void sls_dispose(Node * lst _(out \oset ALL_REACH))
  _(requires srtl(lst))
  _(ensures ALL_REACH == \oset_empty())
{
  _(assume mutable_list(lst))
  _(assume lst != NULL ==> \malloc_root(lst))
  _(ghost ALL_REACH = srtl_reach(lst) ;)

  while(lst != NULL) 
    _(invariant srtl(lst))
    _(invariant ALL_REACH == srtl_reach(lst))
    _(invariant mutable_list(lst))
    _(invariant lst != NULL ==> \malloc_root(lst))
  {
    Node * curr = lst;
    lst = lst->next;
    _(assume mutable_list(lst))
    _(assume lst != NULL ==> \malloc_root(lst))
    free(curr);
    _(ghost ALL_REACH = \oset_diff(ALL_REACH, \oset_singleton(curr)))
  }
}
Exemplo n.º 27
0
void SetTest::testCAPI() {
	SET localset;
	SET remoteset;
	SET_CONFIG localconfig = set_create_config();
	SET_CONFIG remoteconfig = set_create_config();
	CPPUNIT_ASSERT(set_init(&localset,localconfig) == 0);
	CPPUNIT_ASSERT(set_init(&remoteset,remoteconfig) == 0);
	CPPUNIT_ASSERT(set_empty(&localset));
	CPPUNIT_ASSERT(set_empty(&remoteset));
	CPPUNIT_ASSERT(set_max_size(&localset) == localconfig.bf_max_elements);
	CPPUNIT_ASSERT(set_max_size(&remoteset) == remoteconfig.bf_max_elements);
	CPPUNIT_ASSERT(set_size(&localset) == 0);
	CPPUNIT_ASSERT(set_size(&remoteset) == 0);
	CPPUNIT_ASSERT(set_insert_string(&localset, "bla1"));
	CPPUNIT_ASSERT(set_insert_string(&remoteset, "bla2"));
	CPPUNIT_ASSERT(set_size(&localset) == 1);
	CPPUNIT_ASSERT(set_size(&remoteset) == 1);
	CPPUNIT_ASSERT(set_find_string(&localset, "bla1"));
	CPPUNIT_ASSERT(set_find_string(&remoteset, "bla2"));
	CPPUNIT_ASSERT(!set_find_string(&localset, "bla2"));
	CPPUNIT_ASSERT(!set_find_string(&remoteset, "bla1"));

	CPPUNIT_ASSERT(set_insert_string(&localset, "bla3"));
	CPPUNIT_ASSERT(set_size(&localset) == 2);
	CPPUNIT_ASSERT(set_erase_string(&localset, "bla3"));
	CPPUNIT_ASSERT(set_size(&localset) == 1);
	SET_SYNC_HANDLE localprocess;
	SET_SYNC_HANDLE remoteprocess;
	set_sync_init_handle(&localset, &localprocess);
	set_sync_init_handle(&remoteset, &remoteprocess);

	CPPUNIT_ASSERT(!set_sync_done(&localprocess));
	CPPUNIT_ASSERT(!set_sync_done(&remoteprocess));


	CPPUNIT_ASSERT(set_sync_min_bf_buffer(&localprocess)==1);
	CPPUNIT_ASSERT(set_sync_min_trie_buffer(&localprocess)==20*2);
	CPPUNIT_ASSERT(set_sync_min_trie_buffer(&localprocess)<=set_sync_min_buffer(&localprocess));

	// BF Sync
	std::size_t buffersize = 100;
	unsigned char buffer[buffersize];
	std::size_t sending;
	diff_callback * callback = &localset_callback;
	while (set_sync_bf_output_avail(&localprocess) == 1) {
		sending = set_sync_bf_read_next_chunk(&localprocess, buffer, buffersize);
		set_sync_bf_process_chunk(&remoteprocess, buffer, sending, callback, &localset);
	}
	while (set_sync_bf_output_avail(&remoteprocess) == 1) {
		sending = set_sync_bf_read_next_chunk(&remoteprocess, buffer, buffersize);
		set_sync_bf_process_chunk(&localprocess, buffer, sending, callback, &remoteset);
	}

	// BF SYNC DONE AND SET SHOULD BE EQUAL, SO ADDING A DIFF
	CPPUNIT_ASSERT(set_insert_string(&localset, "diff"));

	// Trie Sync
	size_t treecutsize = 2 * 20;
	unsigned char treecut[treecutsize];
	size_t subtriesize;
	std::size_t ackbuffersize = 20;
	unsigned char ackbuffer[ackbuffersize];
	std::size_t numberOfAcks;
	std::size_t acksize;

	while (!set_sync_done(&localprocess) && !set_sync_done(&remoteprocess)) {
		if (set_sync_trie_subtrie_output_avail(&localprocess)) {
			subtriesize = set_sync_trie_get_subtrie(&localprocess, treecut,
					treecutsize);
			CPPUNIT_ASSERT(subtriesize > 0);
			acksize = set_sync_trie_process_subtrie(&remoteprocess, treecut,
					subtriesize);
			CPPUNIT_ASSERT(acksize > 0);
		}
		if (set_sync_trie_acks_avail(&localprocess)) {
			acksize = set_sync_trie_read_acks(&localprocess, ackbuffer,
					ackbuffersize, &numberOfAcks);
			CPPUNIT_ASSERT(numberOfAcks > 0);
			CPPUNIT_ASSERT(acksize > 0);
			set_sync_trie_process_acks(&remoteprocess, ackbuffer, acksize,
					numberOfAcks, callback, &localset);
		}
		if (set_sync_trie_subtrie_output_avail(&remoteprocess)) {
			subtriesize = set_sync_trie_get_subtrie(&remoteprocess, treecut,
					treecutsize);
			CPPUNIT_ASSERT(subtriesize > 0);
			acksize = set_sync_trie_process_subtrie(&localprocess, treecut,
					subtriesize);
			CPPUNIT_ASSERT(acksize > 0);
		}
		if (set_sync_trie_acks_avail(&remoteprocess)) {
			acksize = set_sync_trie_read_acks(&remoteprocess, ackbuffer,
					ackbuffersize, &numberOfAcks);
			CPPUNIT_ASSERT(numberOfAcks > 0);
			CPPUNIT_ASSERT(acksize > 0);
			set_sync_trie_process_acks(&localprocess, ackbuffer, acksize,
					numberOfAcks, callback, &remoteset);
		}
	}
	// TRIES SHOULD BE EQUAL -> TEST IT
	unsigned char localroot[20];
	unsigned char remoteroot[20];
	CPPUNIT_ASSERT(set_sync_get_root_hash(&localprocess, localroot)==0);
	CPPUNIT_ASSERT(set_sync_get_root_hash(&remoteprocess, remoteroot)==0);
	CPPUNIT_ASSERT(set_sync_is_equal_to_hash(&localprocess,remoteroot));
	CPPUNIT_ASSERT(set_sync_is_equal_to_hash(&remoteprocess,localroot));

	// TRANSMITTED DATA TEST
	CPPUNIT_ASSERT(set_sync_received_bytes(&localprocess) == set_sync_sent_bytes(&remoteprocess));
	CPPUNIT_ASSERT(set_sync_received_bytes(&remoteprocess) == set_sync_sent_bytes(&localprocess));

	CPPUNIT_ASSERT(set_sync_free_handle(&localprocess)==0);
	CPPUNIT_ASSERT(set_sync_free_handle(&remoteprocess)==0);
	CPPUNIT_ASSERT(set_free(&localset)==0);
	CPPUNIT_ASSERT(set_free(&remoteset)==0);
}
Exemplo n.º 28
0
Arquivo: ubb.c Projeto: aunali1/exopc
/* 
 * Make sure that the before set is nil --- need to test on all
 * udf's. 
 */
int meta_init(void* meta, ubb_p up) {
	return set_empty(ubb_run(meta, up, 0)) ?
		0 : -1;
}
Exemplo n.º 29
0
/**************************************************************************
 *
 *N  fcs_relate_list
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Read the feature class schema table and create the list of
 *    tables to chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    fcname       <input> == (char *) feature class name.
 *    start_table  <input> == (char *) table to start from.
 *    end_table    <input> == (char *) table to end with.
 *    fcs          <input> == (vpf_table_type) feature class schema table.
 *    fcs_relate_list <output> == (linked_list_type) list of tables to
 *                                chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type fcs_relate_list( char *fcname, char *start_table,
				  char *end_table, vpf_table_type fcs )
{
   linked_list_type rlist;
   vpf_relate_struct rstruct;
   set_type fcset, set1, set2;
   char tablename[255], *buf, expr[255];
   row_type row;
   long int rownum,n;
   int TABLE1_, KEY1_, TABLE2_, KEY2_;

   rlist = ll_init();

   sprintf(expr,"FEATURE_CLASS = %s",fcname);

   fcset = query_table(expr,fcs);

   if (set_empty(fcset)) {
      set_nuke(&fcset);
      return rlist;
   }

   TABLE1_ = table_pos("TABLE1",fcs);
   KEY1_ = table_pos("FOREIGN_KEY",fcs);
   if (KEY1_ < 0) KEY1_ = table_pos("TABLE1_KEY",fcs);
   TABLE2_ = table_pos("TABLE2",fcs);
   KEY2_ = table_pos("PRIMARY_KEY",fcs);
   if (KEY2_ < 0) KEY2_ = table_pos("TABLE2_KEY",fcs);

   strcpy( tablename, start_table );
   while (1) {
      sprintf(expr,"TABLE1 = %s",tablename);

      set1 = query_table(expr,fcs);
      set2 = set_intersection(set1,fcset);
      set_nuke(&set1);
      if (set_empty(set2)) {
	 set_nuke(&fcset);
	 set_nuke(&set2);
	 return rlist;
      }
      rownum = set_min(set2);

      set_nuke(&set2);

      row = get_row(rownum,fcs);

      buf = (char *)get_table_element(TABLE1_,row,fcs,NULL,&n);
      strcpy(rstruct.table1,buf);
      rightjust(rstruct.table1);
      free(buf);

      buf = (char *)get_table_element(KEY1_,row,fcs,NULL,&n);
      strcpy(rstruct.key1,buf);
      rightjust(rstruct.key1);
      free(buf);

      buf = (char *)get_table_element(TABLE2_,row,fcs,NULL,&n);
      strcpy(rstruct.table2,buf);
      rightjust(rstruct.table2);
      free(buf);

      buf = (char *)get_table_element(KEY2_,row,fcs,NULL,&n);
      strcpy(rstruct.key2,buf);
      rightjust(rstruct.key2);
      free(buf);

      rstruct.degree = R_ONE;  /* Default */

      free_row( row, fcs );

      if (table_in_list(rstruct.table1, rlist)) break;

      ll_insert( &rstruct, sizeof(rstruct), ll_last(rlist) );

      strcpy( tablename, rstruct.table2 );

      if (ossim_strcasecmp(tablename,end_table)==0) break;
   }

   set_nuke(&fcset);

   return rlist;
}
Exemplo n.º 30
0
/*
 * sub_unweighted_single()
 *
 * Recursion function for searching for a single clique of size min_size.
 *
 *    table    - subset of the vertices in graph
 *    size     - size of table
 *    min_size - size of clique to look for within the subgraph
 *               (decreased with every recursion)
 *    g        - the graph
 *
 * Returns TRUE if a clique of size min_size is found, FALSE otherwise.
 * If a clique of size min_size is found, it is stored in current_clique.
 *
 * clique_size[] for all values in table must be defined and correct,
 * otherwise inaccurate results may occur.
 */
static boolean sub_unweighted_single(int *table, int size, int min_size,
				     graph_t *g) {
	int i;
	int v;
	int *newtable;
	int *p1, *p2;

	/* Zero or one vertices needed anymore. */
	if (min_size <= 1) {
		if (size>0 && min_size==1) {
			set_empty(current_clique);
			SET_ADD_ELEMENT(current_clique,table[0]);
			return TRUE;
		}
		if (min_size==0) {
			set_empty(current_clique);
			return TRUE;
		}
		return FALSE;
	}
	if (size < min_size)
		return FALSE;

	/* Dynamic memory allocation with cache */
	if (temp_count) {
		temp_count--;
		newtable=temp_list[temp_count];
	} else {
		newtable=malloc(g->n * sizeof(int));
	}

	for (i = size-1; i >= 0; i--) {
		v = table[i];

		if (clique_size[v] < min_size)
			break;
		/* This is faster when compiling with gcc than placing
		 * this in the for-loop condition. */
		if (i+1 < min_size)
			break;

		/* Very ugly code, but works faster than "for (i=...)" */
		p1 = newtable;
		for (p2=table; p2 < table+i; p2++) {
			int w = *p2;
			if (GRAPH_IS_EDGE(g, v, w)) {
				*p1 = w;
				p1++;
			}
		}

		/* Avoid unneccessary loops (next size == p1-newtable) */
		if (p1-newtable < min_size-1)
			continue;
		/* Now p1-newtable >= min_size-1 >= 2-1 == 1, so we can use
		 * p1-newtable-1 safely. */
		if (clique_size[newtable[p1-newtable-1]] < min_size-1)
			continue;

		if (sub_unweighted_single(newtable,p1-newtable,
					  min_size-1,g)) {
			/* Clique found. */
			SET_ADD_ELEMENT(current_clique,v);
			temp_list[temp_count++]=newtable;
			return TRUE;
		}
	}
	temp_list[temp_count++]=newtable;
	return FALSE;
}