Esempio n. 1
0
unsigned int DisjointSets<T, hasher>::merge_classes( 
    unsigned int c1, 
    unsigned int c2 
    ) {
  //get class representatives
  const unsigned int c1_rep = get_rep(c1) ;
  const unsigned int c2_rep = get_rep(c2) ;
  //if the classes are already merged, do nothing
  if(c1_rep == c2_rep) return c1_rep ;

  //merge
  //get the class ranks
  const unsigned int c1_rank = get_rank(c1_rep) ;
  const unsigned int c2_rank = get_rank(c2_rep) ;
  if(c1_rank < c2_rank) {
    //tree for c2 is deeper, use c2 as root
    set_rep(c1_rep, c2_rep) ;
    return c2_rep ;
  } else if(c2_rank < c1_rank) {
    //tree for c1 is deeper, use c1 as root
    set_rep(c2_rep, c1_rep) ;
    return c1_rep ;
  } else {
    //trees have the same depth, use c1 as root and increase its depth
    set_rep(c2_rep, c1_rep) ;
    set_rank(c1_rep, c1_rank+1) ;
    return c1_rep ;
  }
}
Esempio n. 2
0
unsigned int DisjointSets<T, hasher>::get_rep( unsigned int c ) {
  if(nodes_[c].rep != c) {
    //the element is within a class with a different root
    nodes_[c].rep = get_rep(nodes_[c].rep) ;
  }
  //return the representative
  return nodes_[c].rep ;
}
Esempio n. 3
0
int	broadcast(t_stck *s, int fd, t_wait *t)
{
  char	*cmd;
  char	*tmp;
  int	k;
  int	i;

  cmd = t->cmd + 10;
  i = 3;
  tmp = Xmalloc(strlen(cmd) + 32);
  while (++i <= s->max_fd)
    {
      if (s->fds[i].type != FD_IA || i == fd)
	continue;
      k = get_rep(s, &(s->fds[fd]), &(s->fds[i]));
      memset(tmp, 0, strlen(cmd) + 32);
      sprintf(tmp, "message %d,%s", k, cmd);
      send_one(tmp, i, s);
    }
  send_one("ok", fd, s);
  event_broadcast(s, fd, cmd);
  return (0);
}
 //! unary- Allows for dd = -date_duration(2); -> dd == -2
 date_duration operator- ()const
 {
   return date_duration(get_rep() * (-1));
 }
Esempio n. 5
0
 //! unary- Allows for dd = -date_duration(2); -> dd == -2
 date_duration operator-() const
 {
     return date_duration<duration_rep_traits>(get_rep() * (-1));
 }
Esempio n. 6
0
//char* expand_macro(char* p_macro)
char* macro_proc(char* p_macro)
{
  char *p, *pm, *pd;
  int i, k;
  expan_info_t stack[MAX_MACROS];
  int top;
  char ch;
  int n;
  char s[33];
  char rep[81];
  int ret;

  p = p_macro;
  memset(stack, 0, sizeof(stack));
  top = -1;
  i = 0;
  k = 0;
  while(ch = p[i]) {
    switch( ch ) {
    case '[':
      if(top>=0) stack[top].nargs = n;
      top++;
      i++;
      n = 0;
      ret = 0;
      break;
    case ']':
      s[k] = '\0';
      k = 0;
      if(0==n) {
	strcpy(stack[top].name, s);
	stack[top].nargs = 0;
	n++;
      } else {
	strcpy(stack[top].args[n-1], s);
	stack[top].nargs = n;
	n++;
      }

      pm = stack[top].name;
      if(0 == strcmp(pm, "def")) { //install macro
	strcpy(macro_table[entry_cnt].p_mcr[0], stack[top].args[0]);
	strcpy(macro_table[entry_cnt].p_mcr[1], stack[top].args[1]);
	entry_cnt++;
      } else {
	pd = get_macro_def(pm);
	if(pd)
	  ret = get_rep(pd, &stack[top], rep, sizeof(rep));
	//printf("%s", rep);
      }
      //n = stack[top].nargs;
      top--;
      if(top>=0) {
	n = stack[top].nargs;
	if(0 == n)
	  strcpy(stack[top].name, rep);
	else if(n > 0)
	  strcpy(stack[top].args[n-1], rep);
	n++;
	if(',' == p[i+1])
	  i+=2; //eat ']' and next ','
      } else if(ret > 0) {
	memset(stack, 0, sizeof(stack));
	printf("%s", rep);
	i++;
      } else
	i++;
      break;
    case ',':
      s[k] = '\0';
      k = 0;
      if(0==n) {
	strcpy(stack[top].name, s);
	stack[top].nargs = 0;
	n++;
      } else {
	strcpy(stack[top].args[n-1], s);
	stack[top].nargs = n;
	n++;
      }
      i++;
      break;
    case '\n':
      putchar(ch);
      i++;
      break;
    default:
      if(top>=0)
	s[k++] = ch;
      else
	putchar(ch);
      i++;
      break;
    }

      
  }
}
Esempio n. 7
0
unsigned int DisjointSets<T, hasher>::item_class( const T& item ) {
  item_it it = items_.find(item) ;
  return it == items_.end() ? NO_CLASS : get_rep(it->second) ;
}