Exemplo n.º 1
0
 cache_set( InputIterator first, InputIterator last,
           size_type n, const hasher& h, 
           const key_equal& k )
     : m_ht(  2 * n, h, k )
 {
     m_ht.insert( first, last );
 }
Exemplo n.º 2
0
//***********************************************************************
void inpSet(HT& T, char name)
{
	T.clear();
	short size, t;
	cout << "Ввод множества " << name << endl;
	cout << "Введите количество элементов от 0 до 16:" << endl;
	do {
		cin.clear();
		cin.sync();
		cin >> size;
		if (size < 0 || size>16 || cin.fail())
			cout << "Число от 0 до 16!\nВведите повторно:";
	} while (size < 0 || size>16 || cin.fail());
	cout << "Введите элементы множества от 0 до 99 без повторов" << endl;
	for (int i = 0; i < size;) {
		cin.clear();
		cin.sync();
		cout << i << "-е число " << name << ":";
		cin >> t;
		if (t<0 || t>99 || cin.fail())
			cout << "Число от 0 до 99!\nВведите другое значение\n";
		else
			T.insert(HT::value_type(t, i));
			++i;
	}
	cout << endl;
}
Exemplo n.º 3
0
 inline static
 void set(HT &ht,K const& key,V const &v=V())
 {
     std::pair<typename HT::iterator,bool> r=ht.insert(value_type(key,v));
     if (!r.second)
         const_cast<V&>(r.first->second)=v;
 }
Exemplo n.º 4
0
//***********************************************************************
void genSet(HT& T)
{
	T.clear();
	int t = rand() % (arrPower + 1);
	for (int i = 0; i < t; ++i) {
		T.insert(HT::value_type((rand() % hPower + 1), i));
	}
}
Exemplo n.º 5
0
int main(){
	HT myTable;
	cout<<"Inserting..."<<endl;
	myTable.insert(2,"mike");
	myTable.insert(12,"kalgecin");
	myTable.insert(52,"michael");
	//cout<<"1"<<endl;
	myTable.insert(59,"yasin");
	//cout<<2<<endl;
	myTable.insert(51,"frank");
	//cout<<3<<endl;
	cout<<"Done inserting"<<endl;
	try{
		cout<<"kalgecin is "<<myTable.find("kalgecin")<<endl;
		cout<<"69 is "<<myTable.find(59)<<endl;
	}catch(string s){
		cout<<s<<endl;
	}
	return 0;
}
Exemplo n.º 6
0
void mapOr(const HT& leftExp, const HT& rightExp, HT& result)
{
	result.clear();
	vector<int> vl(leftExp.size()), vr(rightExp.size()), vm;
	transform(leftExp.begin(), leftExp.end(), vl.begin(), keySel);   
	transform(rightExp.begin(), rightExp.end(), vr.begin(), keySel); 
	sort(vl.begin(), vl.end());
	sort(vr.begin(), vr.end());
	set_union(vl.cbegin(), vl.cend(), vr.cbegin(), vr.cend(), inserter(vm, vm.begin()));
	int i=0;
	for (auto it = vm.cbegin(); it != vm.cend(); ++it, ++i)
		result.insert(HT::value_type((*it), i));
}
Exemplo n.º 7
0
//***********************************************************************
void concat(HT& leftExp, const HT &rightExp)
{
	if (!rightExp.empty()) {
		int newPos = leftExp.size();
		int s = rightExp.size();
		for (int i = 0; i < s; ++i) {
			for (HT::const_iterator it = rightExp.cbegin(); it != rightExp.cend(); ++it)
				if (it->second == i) {
					leftExp.insert(HT::value_type((*it).first, newPos++));
					break;
				}
		}
	}
}
Exemplo n.º 8
0
//***********************************************************************
int fileSet(HT& T, char name='a')
{
	T.clear();
	FILE* file;
	int size, t;
	char n[6] = " .txt";
	n[0] = name;
	if (!(file = fopen(n, "r")))
		return 1;         //Файла не существует
	fseek(file, 0, SEEK_END);
	if (!ftell(file))
		return 2;         //Файл пустой
	rewind(file);
	fscanf(file, "%d", &size);
	for (int i = 0; i<size; ++i)
	{
		fgetc(file);
		fscanf(file, "%d", &t);
		T.insert(HT::value_type(t, i));
	}
	fclose(file);
	return 0;
}
Exemplo n.º 9
0
 /** Not standard iterator insertion
  * 
  * @param it iterator that mark the insertion position
  * @param obj the new value for the item
  * @return an iterator to the modified item
  */
 iterator insert( iterator it, const value_type& obj )
 { return m_ht.insert( obj ).first; }
Exemplo n.º 10
0
 void insert( InputIterator first, InputIterator last )
 { m_ht.insert( first, last ); }
Exemplo n.º 11
0
 /** Insert an item in the set.
  *
  *  The item, the pair(key, data), will be inserted in the hash table.
  *  In case of a key hash collision, the inserted item will replace the
  *  existing one.
  *
  *  Following the @a DiscardFunction policy there will be a notification
  *  that old item has been replaced.
  * 
  *  @return A @p pair<iterator,bool> which contain an #iterator to the
  *  inserted item and @p true if the item was correctly inserted, or @p
  *  false if the item was not inserted.
  */
 pair<iterator,bool> insert( const value_type& obj )
 { return m_ht.insert( obj ); }
Exemplo n.º 12
0
 cache_set( InputIterator first, InputIterator last,
           size_type n, const hasher& h )
     : m_ht(  2 * n, h )
 {
     m_ht.insert( first, last );
 }
Exemplo n.º 13
0
 cache_set( InputIterator first, InputIterator last, size_type n )
         : m_ht(  2 * n )
 {
     m_ht.insert( first, last );
 }
Exemplo n.º 14
0
 cache_set( InputIterator first, InputIterator last )
     : m_ht(  2 * std::distance( first, last ) )
 {
     m_ht.insert( first, last );
 }
Exemplo n.º 15
0
 inline static
 insert_ret insert(HT &ht,K const& key,V const &v=V())
 {
     return ht.insert(value_type(key,v));
 }
Exemplo n.º 16
0
 /** Non-stardard insert method.
  *  Insert an (key,data) pair in the map.
  *
  *  @warning Don't use it if you want to maintain source code
  *  compatibility with other @a Associative @a Containers.
  *  @see insert( const value_type& )
  */
 pair<iterator,bool> insert( const key_type& key, const data_type& data )
 { return m_ht.insert( value_type( key, data ) ); }