示例#1
0
文件: ltablib.c 项目: guodawei/lua
/*
** Does the partition: Pivot P is at the top of the stack.
** precondition: a[lo] <= P == a[up-1] <= a[up],
** so it only needs to do the partition from lo + 1 to up - 2.
** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]
** returns 'i'.
*/
static IdxT partition (lua_State *L, IdxT lo, IdxT up) {
  IdxT i = lo;  /* will be incremented before first use */
  IdxT j = up - 1;  /* will be decremented before first use */
  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */
  for (;;) {
    /* next loop: repeat ++i while a[i] < P */
    while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */
        luaL_error(L, "invalid order function for sorting");
      lua_pop(L, 1);  /* remove a[i] */
    }
    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */
    /* next loop: repeat --j while P < a[j] */
    while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {
      if (j < i)  /* j < i  but  a[j] > P ?? */
        luaL_error(L, "invalid order function for sorting");
      lua_pop(L, 1);  /* remove a[j] */
    }
    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */
    if (j < i) {  /* no elements out of place? */
      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */
      lua_pop(L, 1);  /* pop a[j] */
      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */
      set2(L, up - 1, i);
      return i;
    }
    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */
    set2(L, i, j);
  }
}
bool addRecursive(CuckooMap* map, uint64_t key, uint64_t value, int depth)
{
	if(depth > MAX_LOOP)
	{
		return false;
	}
	//if its empty in the first table, add it there
	if(getKey1(map, key) == NONE)
	{
		set1(map, key, value);
	}
	//if its empty in the second table, add it there
	else if(getKey2(map, key) == NONE)
	{
		set2(map, key, value);
	}
	//if both are occupied, randomly displace one and re-add the displaced one
	else if((xorshf96() & 1) == 0)
	{
		uint64_t pushedKey = getKey1(map, key);
		uint64_t pushedValue = getValue1(map, key);
		set1(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	else
	{
		uint64_t pushedKey = getKey2(map, key);
		uint64_t pushedValue = getValue2(map, key);
		set2(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	return true;
}
示例#3
0
文件: ltablib.c 项目: guodawei/lua
/*
** QuickSort algorithm (recursive function)
*/
static void auxsort (lua_State *L, IdxT lo, IdxT up,
                                   unsigned int rnd) {
  while (lo < up) {  /* loop for tail recursion */
    IdxT p;  /* Pivot index */
    IdxT n;  /* to be used later */
    /* sort elements 'lo', 'p', and 'up' */
    lua_geti(L, 1, lo);
    lua_geti(L, 1, up);
    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */
      set2(L, lo, up);  /* swap a[lo] - a[up] */
    else
      lua_pop(L, 2);  /* remove both values */
    if (up - lo == 1)  /* only 2 elements? */
      return;  /* already sorted */
    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */
      p = (lo + up)/2;  /* middle element is a good pivot */
    else  /* for larger intervals, it is worth a random pivot */
      p = choosePivot(lo, up, rnd);
    lua_geti(L, 1, p);
    lua_geti(L, 1, lo);
    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */
      set2(L, p, lo);  /* swap a[p] - a[lo] */
    else {
      lua_pop(L, 1);  /* remove a[lo] */
      lua_geti(L, 1, up);
      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */
        set2(L, p, up);  /* swap a[up] - a[p] */
      else
        lua_pop(L, 2);
    }
    if (up - lo == 2)  /* only 3 elements? */
      return;  /* already sorted */
    lua_geti(L, 1, p);  /* get middle element (Pivot) */
    lua_pushvalue(L, -1);  /* push Pivot */
    lua_geti(L, 1, up - 1);  /* push a[up - 1] */
    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */
    p = partition(L, lo, up);
    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */
    if (p - lo < up - p) {  /* lower interval is smaller? */
      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */
      n = p - lo;  /* size of smaller interval */
      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */
    }
    else {
      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */
      n = up - p;  /* size of smaller interval */
      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */
    }
    if ((up - lo) / 128 > n) /* partition too imbalanced? */
      rnd = l_randomizePivot();  /* try a new randomization */
  }  /* tail call auxsort(L, lo, up, rnd) */
}
示例#4
0
TSet TSet::operator-(const int Elem) // разность с элементом
{
	TBitField s(MaxPower);
	s.SetBit(Elem);
	TSet set2(BitField & s);
  return set2;
}
示例#5
0
TSet TSet::operator+(const int Elem) // объединение с элементом
{
	TBitField s(MaxPower);
	s.SetBit(Elem);
	TSet set2(BitField | s);
  return set2;
}
示例#6
0
TEST(TSet, compare_two_sets_of_non_equal_sizes)
{
  const int size1 = 4, size2 = 6;
  TSet set1(size1), set2(size2);

  EXPECT_EQ(1, set1 != set2);
}
示例#7
0
TEST(IntervalTest, IntersectionTest)
{
  Interval<int> interval((Bound<int>::open(4), Bound<int>::closed(6)));
  Interval<int> interval2((Bound<int>::closed(1), Bound<int>::closed(5)));
  Interval<int> interval3((Bound<int>::closed(7), Bound<int>::closed(8)));

  IntervalSet<int> set((Bound<int>::closed(1), Bound<int>::closed(3)));
  IntervalSet<int> set2((Bound<int>::open(2), Bound<int>::open(4)));
  IntervalSet<int> set3((Bound<int>::open(6), Bound<int>::closed(7)));

  EXPECT_FALSE(set.intersects(interval));
  EXPECT_TRUE(set2.intersects(interval2));
  EXPECT_TRUE(set3.intersects(interval3));

  EXPECT_FALSE(set2.intersects(interval));
  EXPECT_TRUE(set2.intersects(interval2));
  EXPECT_FALSE(set2.intersects(interval3));

  EXPECT_TRUE(set.intersects(set2));
  EXPECT_TRUE(set2.intersects(set));
  EXPECT_FALSE(set3.intersects(set2));

  EXPECT_TRUE(interval.intersects(interval2));
  EXPECT_FALSE(interval2.intersects(interval3));
  EXPECT_FALSE(interval3.intersects(interval));
}
示例#8
0
int main(int argc, char *argv[])
{
  /* sets to be used for testing */
  char s[5] = {'1','2','3','4','\0'};
  char t[4] = {'1','2','3','\0'};
  char u[1] = {'\0'};
  char v[4] = {'x','y','z','\0'};
  
  /* sets to contain results */
  char a[SIZE];
  char b[SIZE];
  char c[SIZE];
  char d[SIZE];
  
  /* SetTypes for testing */
  SetType set1(s);
  SetType set2(t);
  SetType set3(u);
  
  /* test of is_empty. Should output "Set is empty" followed by "Set is not
      empty */
  set3.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n";
  set1.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n";
  
  /* test of is_equal. Should output "s is equal" followed by "t is not equal" 
  */
  set1.is_equal(s) ? cout << "s is equal\n" : cout << "s is not equal\n";
  set1.is_equal(t) ? cout << "t is equal\n" : cout << "t is not equal\n";
  
  /* test of is_member. Should output "4 is a member" followed by "8 is not a
      member */
  set1.is_member('4') ? cout << "4 is a member\n" : cout << "4 is not a member\n";
  set1.is_member('8') ? cout << "8 is a member\n" : cout << "8 is not a member\n";
  
  /* test of is_subset. Should output "t is a subset" followed by "v is not a
      subset */
  set1.is_subset(t) ? cout << "t is a subset\n" : cout << "t is not a subset\n";
  set1.is_subset(v) ? cout << "v is a subset\n" : cout << "v is not a subset\n";
  
  /* test of setunion. Should output all elements from s and v. Implicitly
      tests the write function. */
  set1.setunion(v, a);
  SetType set4(a);
  set4.write();
  
  /* test of intersection. Should output all elements in both t and s. */
  set1.intersection(t, b);
  SetType set5(b);
  set5.write();
  
  /* test of difference. Should output all elements only in t or only in s */
  set1.difference(t, d);
  SetType set7(d);
  set7.write();

  /* return success */
  return 0;
}
示例#9
0
void parser_imp::code_with_callbacks(std::function<void()> && f) {
    m_script_state->apply([&](lua_State * L) {
            set_io_state    set1(L, m_io_state);
            set_environment set2(L, m_env);
            m_script_state->exec_unprotected([&]() {
                    f();
                });
        });
}
示例#10
0
文件: lext.c 项目: whoopdedo/lgscript
static int t_reverse (lua_State *L) {
  int u = aux_getn(L, 1);
  int l = 1;
  while (l < u) {
    get2(L, l, u);
    set2(L, l, u);
    ++l; --u;
  }
  return 0;
}
示例#11
0
DWORD U16Parser::Serialize(BYTE* data,DWORD size)
{
	if (size<2)
		return -1;

	//Serialize
	set2(data,0,value);	

	return 2;
}
示例#12
0
TEST(TSet, can_assign_set_of_equal_size)
{
  const int size = 4;
  TSet set1(size), set2(size);
  // set1 = {1, 3}
  set1.InsElem(1);
  set1.InsElem(3);
  set2 = set1;

  EXPECT_EQ(set1, set2);
}
示例#13
0
SqlInsert::operator SqlStatement() const {
    String s = "insert into " + table.Quoted();
    if(!set1.IsEmpty()) {
        s << set1();
        if(sel.IsValid())
            s << ' ' << SqlStatement(sel).GetText();
        else if(!set2.IsEmpty())
            s << " values " << set2();
    }
    return SqlStatement(s);
}
示例#14
0
TEST(TSet, can_assign_set_of_greater_size)
{
  const int size1 = 4, size2 = 6;
  TSet set1(size1), set2(size2);
  // set1 = {1, 3}
  set1.InsElem(1);
  set1.InsElem(3);
  set2 = set1;

  EXPECT_EQ(set1, set2);
}
示例#15
0
static void test_copy(std::vector<T> const& data)
{
  sib::vector_set<T> set1;
  for(std::size_t ii = 0; ii != data.size(); ++ii)
    set1.insert(data[ii]);
  sib::vector_set<T> set2(const_cast<sib::vector_set<T> const&>(set1));
  EXPECT_EQ(set1.size(), set2.size());
  typename sib::vector_set<T>::const_iterator i1 = set1.begin();
  typename sib::vector_set<T>::const_iterator i2 = set2.begin();
  for(std::size_t ii = 0; ii != data.size(); ++ii)
    EXPECT_TRUE(*(i1++) == *(i2++));
}
示例#16
0
TEST(TSet, compare_two_equal_sets)
{
  const int size = 4;
  TSet set1(size), set2(size);
  // set1 = set2 = {1, 3}
  set1.InsElem(1);
  set1.InsElem(3);
  set2.InsElem(1);
  set2.InsElem(3);

  EXPECT_EQ(set1, set2);
}
示例#17
0
TEST(TSet, can_assign_set_of_less_size)
{
  const int size1 = 6, size2 = 4;
  TSet set1(size1), set2(size2);
  // set1 = {1, 3, 5}
  set1.InsElem(1);
  set1.InsElem(3);
  set1.InsElem(5);
  set2 = set1;

  EXPECT_EQ(set1, set2);
}
/*
 this function add  a new item to svMapRaw.
 svMapRaw is  from a postfix to  a vector of possible predict words.
 
*/
void AddElem(	Flex2WordMap& svMapRaw, 
				const string &Postfix, 
				int LemmaInfoNo, 
				const WORD nps,
				const WORD ItemNo,
				const DwordVector& ModelFreq, 
				const vector<CLemmaInfoAndLemma>&	LemmaInfos
				)
{

	// ============= determine the part of speech (nps)
	const CLemmaInfo& LemmaInfo =  LemmaInfos[LemmaInfoNo].m_LemmaInfo;
	

	// ============= adding to  svMapRaw, if not exists, otherwise update frequence
	CPredictWord set2(1, LemmaInfoNo, nps, ItemNo);
	Flex2WordMap::iterator svMapIt = svMapRaw.find(Postfix);

	if( svMapIt==svMapRaw.end() )
	{
		vector<CPredictWord> set2vec;
		set2vec.push_back(set2);
		svMapRaw[Postfix] = set2vec;
	}
	else
	{
		int i=0;
		for( ; i<svMapIt->second.size(); i++ )
		{
			// if postfix, flexia and PartOfSpeech are equal then we should update frequence and exit
			if( svMapIt->second[i].m_nps == set2.m_nps )
			{
				svMapIt->second[i].m_Freq++;

				//  if  the new example is more frequent then we should predict using this example
				const CLemmaInfo& OldLemmaInfo =  LemmaInfos[svMapIt->second[i].m_LemmaInfoNo].m_LemmaInfo;

				if (ModelFreq[LemmaInfo.m_FlexiaModelNo] > ModelFreq[OldLemmaInfo.m_FlexiaModelNo])
				{
					svMapIt->second[i].m_LemmaInfoNo = LemmaInfoNo;
					svMapIt->second[i].m_ItemNo = ItemNo;

				};

				break;
			}
		}
		// if no such part of speech for this postfix and flexia is found
		// then add new item
		if( i>= svMapIt->second.size() )
			svMapIt->second.push_back(set2);
	}
}
示例#19
0
TEST(TSet, triple_one_string_and)
{
	const int size = 4;
	TSet set1(size), set2(size), set3(size), tmp(size), expSet(size);
	set1.InsElem(2);
	set2.InsElem(2);
	set3.InsElem(2);
	expSet = set1 * set2;
	expSet = expSet * set3;
	tmp = set1*set2*set3;

	EXPECT_EQ(expSet, tmp);
}
示例#20
0
TEST(TSet, can_use_sum_for_three_sets)
{
	const int size = 10;
	TSet set0(size), set1(size), set2(size), set3(size), expSet(size);
	set0.InsElem(1);
	set1.InsElem(3);
	set2.InsElem(5);
	set3 = set0 + set1 + set2;
	expSet.InsElem(1);
	expSet.InsElem(3);
	expSet.InsElem(5);
	EXPECT_EQ(expSet, set3);
}
示例#21
0
文件: limiter~.c 项目: Tzero2/pd
static void *limiter_new(t_symbol *s, int argc, t_atom *argv)
{
  t_limiter *x = (t_limiter *)pd_new(limiter_class);
  int i = 0;

  if (argc) set_bufsize(x, atom_getfloat(argv));
  else
    {
      argc = 1;
      set_bufsize(x, 0);
    }

  if (argc > 64)	argc=64;
  if (argc == 0)	argc=1;

  x->number_of_inlets = argc--;

  while (argc--)
    {
      inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
    }

  outlet_new(&x->x_obj, &s_signal);

  x->in = (t_inbuf*)getbytes(sizeof(t_inbuf) * x->number_of_inlets);
  while (i < x->number_of_inlets)
    {
      int n;
      t_sample* buf = (t_sample *)getbytes(sizeof(*buf) * x->buf_size);
      x->in[i].ringbuf		= buf;
      x->in[i].buf_position	= 0;
      for (n = 0; n < x->buf_size; n++) x->in[i].ringbuf[n] = 0.;
      i++;
    }

  x->val1 = (t_limctl *)getbytes(sizeof(t_limctl));
  x->val2 = (t_limctl *)getbytes(sizeof(t_limctl));
  x->cmp = (t_cmpctl *)getbytes(sizeof(t_cmpctl));

  x->cmp->ratio = 1.;
  x->cmp->treshold = 1;

  set1(x, 100, 30, 139);
  set2(x, 110, 5, 14.2);

  x->amplification= 1;
  x->samples_left	= x->still_left = x->mode = 0;

  return (x);
}
示例#22
0
Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w,
			     QMainWindow *mw) : QToolBar(mw, "NT")
  {
    w->attach(&input_point);
    input_point.deactivate();
    w->attach(&input_line);
    input_line.deactivate();
    w->attach(&input_polygon);
    input_polygon.deactivate();

    //set the widget
    widget = w;

    QIconSet set0(QPixmap( (const char**)arrow_small_xpm ),
                  QPixmap( (const char**)arrow_xpm ));
    QIconSet set1(QPixmap( (const char**)point_small_xpm ),
                  QPixmap( (const char**)point_xpm ));
    QIconSet set2(QPixmap( (const char**)line_small_xpm ),
                  QPixmap( (const char**)line_xpm ));
    QIconSet set3(QPixmap( (const char**)polygon_small_xpm ),
                  QPixmap( (const char**)polygon_xpm ));

  but[0] = new QToolButton(this, "Deactivate Layer");
  but[0]->setIconSet(set0);
  but[0]->setTextLabel("Deactivate Layer");
  but[1] = new QToolButton(this, "pointinput layer");
  but[1]->setIconSet(set1);
  but[1]->setTextLabel("Input Point");
  but[2] = new QToolButton(this, "lineinput layer");
  but[2]->setIconSet(set2);
  but[2]->setTextLabel("Input Line");
  but[3] = new QToolButton(this, "polygoninput layer");
  but[3]->setIconSet(set3);
  but[3]->setTextLabel("Input Simple Polygon");

  nr_of_buttons = 4;
  button_group = new QButtonGroup(0, "My_group");
  for(int i = 0; i<nr_of_buttons; i++) {
    button_group->insert(but[i]);
    but[i]->setToggleButton(true);
  }
  button_group->setExclusive(true);

  connect(but[1], SIGNAL(stateChanged(int)),
        &input_point, SLOT(stateChanged(int)));
  connect(but[2], SIGNAL(stateChanged(int)),
        &input_line, SLOT(stateChanged(int)));
  connect(but[3], SIGNAL(stateChanged(int)),
        &input_polygon, SLOT(stateChanged(int)));
}
示例#23
0
TEST(IntervalTest, InfixOperator)
{
  IntervalSet<int> set1(Bound<int>::closed(0), Bound<int>::closed(1));
  IntervalSet<int> set2(Bound<int>::closed(2), Bound<int>::open(3));
  IntervalSet<int> set3(Bound<int>::closed(0), Bound<int>::closed(2));

  EXPECT_EQ(set3, set1 + set2);
  EXPECT_EQ(set3, set1 + (Bound<int>::closed(2), Bound<int>::open(3)));
  EXPECT_EQ(set3, set1 + 2);

  EXPECT_EQ(set1, set3 - set2);
  EXPECT_EQ(set2, set3 - (Bound<int>::closed(0), Bound<int>::closed(1)));
  EXPECT_EQ(set1, set3 - 2);
}
void dlgSelectConnection::OnChangeServer(wxCommandEvent& ev)
{
	if (!GetServer())
		return;

    cbDatabase->Clear();

    int sel=cbServer->GetCurrentSelection();
    if (sel >= 0)
    {
        remoteServer = (pgServer*)cbServer->GetClientData(sel);

        if (!remoteServer->GetConnected())
        {
            remoteServer->Connect(mainForm, remoteServer->GetStorePwd());
            if (!remoteServer->GetConnected())
            {
                wxLogError(wxT("%s"), remoteServer->GetLastError().c_str());
                return;
            }
        }
        if (remoteServer->GetConnected())
        {
            pgSetIterator set1(remoteServer->GetConnection(), 
                wxT("SELECT DISTINCT datname\n")
                wxT("  FROM pg_database db\n")
                wxT(" WHERE datallowconn ORDER BY datname"));

            while(set1.RowsLeft())
                cbDatabase->Append(set1.GetVal(wxT("datname")));

            if (cbDatabase->GetCount())
                cbDatabase->SetSelection(0);

            pgSetIterator set2(remoteServer->GetConnection(), 
                wxT("SELECT DISTINCT usename\n")
                wxT("FROM pg_user db\n")
                wxT("ORDER BY usename"));

            while(set2.RowsLeft())
                cbUsername->Append(set2.GetVal(wxT("usename")));

            if (cbUsername->GetCount())
                cbUsername->SetSelection(0);
        }

    }
    OnChangeDatabase(ev);
}
示例#25
0
TEST(IntervalTest, Constructor)
{
  IntervalSet<int> set(0);

  EXPECT_TRUE(set.contains(0));
  EXPECT_EQ(1u, set.intervalCount());
  EXPECT_EQ(1u, set.size());

  IntervalSet<int> set2(Bound<int>::closed(1), Bound<int>::closed(2));

  EXPECT_TRUE(set2.contains(1));
  EXPECT_TRUE(set2.contains(2));
  EXPECT_EQ(1u, set2.intervalCount());
  EXPECT_EQ(2u, set2.size());
}
示例#26
0
TEST(TSet, check_size_changes_of_the_combination_of_two_sets_of_non_equal_size)
{
  const int size1 = 5, size2 = 7;
  TSet set1(size1), set2(size2), set3(size1);
  // set1 = {1, 2, 4}
  set1.InsElem(1);
  set1.InsElem(2);
  set1.InsElem(4);
  // set2 = {0, 1, 2}
  set2.InsElem(0);
  set2.InsElem(1);
  set2.InsElem(2);
  set3 = set1 + set2;

  EXPECT_EQ(size2, set3.GetMaxPower());
}
示例#27
0
Sprite *Thought_Bubble::copy(boolean also_copy_offsets) {
	Sprite *copied = already_copied(this); // new on 210203
   if (copied != NULL) {
		return(copied);
	};
	Thought_Bubble *copy = new Thought_Bubble(llx,lly,current_priority,width,height); // moved here on 210203 so can deal with circularities better
//	just_copied(this,copy); -- moved into top_level_copy on 210203
// some reason this wasn't really centering it appropriately
// reason is that the bb is wrong since it picked up the first little bubble
//	city_coordinate center_x, center_y;
//	center_location(center_x,center_y);
	Cubby *cubby_copy = NULL;
	// setting and resetting the following flag is not very elegant
	// but since it is an atomic operation there is no problem
	// used by numbers to determine if ok to copy blank to blank
	// and blank cubbies
	//Sprite *saved_tt_top_copy = tt_top_copy; // commented out on 210203 since now uses top_level_copy
	//tt_top_copy = NULL; // no sharing inside of thought bubbles
	UnwindProtect<boolean> set(tt_copying_entire_thought_bubble,TRUE); // in case a robot is in a thought bubble
	UnwindProtect<boolean> set2(tt_dont_connect_things_while_copying,TRUE);
	if (cubby != NULL) { // && cubby->pointer_to_leader() == this) { // commented out on 250103
		cubby_copy = (Cubby *) (cubby->top_level_copy(TRUE,this,copy)); // made top_level on 100203
	};
//   Robot *robot_copy = NULL;
//   if (robot != NULL) {
//      robot_copy = (Robot *) (robot->copy());
//   };
//	if (cubby_copy != NULL) { // commented out on 250103
////		copy->update_display(); // for the receive_cubby to work right
//		copy->receive_cubby(cubby_copy);
//	};
//	copy->move_to(llx,lly);
//	if (saved_width != 0) {
//		copy->set_saved_size(saved_width,saved_height);
//	};
//	tt_copying_entire_thought_bubble = FALSE;
	// replaced the above with the following on 201299
//	tt_top_copy = saved_tt_top_copy;
//   copy->set_priority_fixed(priority_fixed_flag);
	if (cubby_copy != NULL) { // condition new on 280103 - thanks Gordon
		copy->set_cubby(cubby_copy,FALSE);
		copy->add_follower(cubby_copy,TRUE,INSERT_AT_END,TRUE);
		cubby_copy->inside_thought_bubble();
	};
	finish_making_copy(copy,also_copy_offsets); 
	return(copy);
};
示例#28
0
int main()
{
	string str1[] = { "Pooh", "Piglet", "Tigger", "Eeyore" }; 
	string str2[] = { "Pooh", "Heffalump", "Woozles" };
        ostream_iterator< string >  ofile( cout, " " );
		
	set<string,less<string>,allocator> set1( str1, str1+4 );
	set<string,less<string>,allocator> set2( str2, str2+3 );

        cout << "set #1 elements:\n\t";
        copy( set1.begin(), set1.end(), ofile ); cout << "\n\n";

        cout << "set #2 elements:\n\t";
        copy( set2.begin(), set2.end(), ofile ); cout << "\n\n";

	set<string,less<string>,allocator> res;
	set_union( set1.begin(), set1.end(),
		   set2.begin(), set2.end(), 
		   inserter( res, res.begin() ));

        cout << "set_union() elements:\n\t";
        copy( res.begin(), res.end(), ofile ); cout << "\n\n";

	res.clear();
	set_intersection( set1.begin(), set1.end(),
                          set2.begin(), set2.end(),
                          inserter( res, res.begin() ));

        cout << "set_intersection() elements:\n\t";
        copy( res.begin(), res.end(), ofile ); cout << "\n\n";

        res.clear();
        set_difference( set1.begin(), set1.end(),
                        set2.begin(), set2.end(),
                        inserter( res, res.begin() ));

        cout << "set_difference() elements:\n\t";
        copy( res.begin(), res.end(), ofile ); cout << "\n\n";

        res.clear();
        set_symmetric_difference( set1.begin(), set1.end(),
                                  set2.begin(), set2.end(),
                                  inserter( res, res.begin() ));

        cout << "set_symmetric_difference() elements:\n\t";
        copy( res.begin(), res.end(), ofile ); cout << "\n\n";
}
int main ()
{
    RuntimeCmp <int> reverse_order (RuntimeCmp<int>::reverse);

    IntSet set1;
    IntSet set2 (reverse_order);
    set1 = set2;
    assert (set1.key_comp () == set2.key_comp ());
    assert (set1.value_comp () == set2.value_comp ());

    IntMap map1;
    IntMap map2 (reverse_order);
    map1 = map2;
    assert (map1.key_comp () == map2.key_comp ());

    return 0;
}
示例#30
0
TEST(TSet, can_intersect_two_sets_of_equal_size)
{
  const int size = 5;
  TSet set1(size), set2(size), set3(size), expSet(size);
  // set1 = {1, 2, 4}
  set1.InsElem(1);
  set1.InsElem(2);
  set1.InsElem(4);
  // set2 = {0, 1, 2}
  set2.InsElem(0);
  set2.InsElem(1);
  set2.InsElem(2);
  set3 = set1 * set2;
  // expSet = {1, 2}
  expSet.InsElem(1);
  expSet.InsElem(2);

  EXPECT_EQ(expSet, set3);
}