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; }
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 ); }
//*********************************************************************** void getInfSeq(const HT& T, char name) { if (!T.empty()) { cout << name << " = <"; int s = T.size(); for (int i = 0; i < s; ++i) { for (HT::const_iterator it = T.cbegin(); it != T.cend(); ++it) if (it->second == i) { cout << it->first << ' '; break; } } cout << "\b>" << endl; } else cout << name << " - Пустая последовательность!"<<endl; }
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)); }
bool testHashTableFullCoverage(const HT &hashTable, const hyrise::storage::atable_ptr_t &table, const field_list_t &columns) { bool result = true; for (pos_t row = 0; row < table->size(); ++row) { pos_list_t positions = hashTable.get(table, columns, row); if (positions.empty()) { result = false; break; } } return result; }
//*********************************************************************** 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; }
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; }
//*********************************************************************** 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; } } } }
/** Test for empty. * @return true if the cache_set does not contains items. */ bool empty() const { return m_ht.empty(); }
/** Get the maximum size of the set. * This corresponds to the maximum number of item that the set can * contain. * @return the maximum number of elements */ size_type max_size() const { return m_ht.max_size(); }
/** Get the number of allocated buckets. * This corresponds to the max_size() value. * @return the number of buckets * @see max_size */ size_type bucket_count() const { return m_ht.bucket_count(); }
/** Swap the content of two cache_set. * * @param other another cache_set */ void swap( cache_set& other ) { m_ht.swap( other.m_ht ); }
/** Get the size of the cache_set. * The size represent the number of non-empty elements that can be * found in the container. * @return the number of elements in the set */ size_type size() const { return m_ht.size(); }
/// Get a const iterator to the end of the table const_iterator end() const { return m_ht.end(); }
cache_set( InputIterator first, InputIterator last, size_type n, const hasher& h ) : m_ht( 2 * n, h ) { m_ht.insert( first, last ); }
/** Get the number of hash key collisions. * * @return the number of hash key collisions */ size_type num_collisions() const { return m_ht.num_collisions(); }
//*********************************************************************** int excl(HT& leftExp, const HT& rightExp) { int stPos = -1, curPos = -1, step = 0; if (!rightExp.empty() && !leftExp.empty()) { if (leftExp.size() < rightExp.size()) return 1; int sizeL = leftExp.size(); int sizeR = rightExp.size(); for (int i = 0; i < sizeL && (curPos - stPos + 1) != sizeR; ++i) { for (HT::const_iterator itL = leftExp.cbegin(); itL != leftExp.cend(); ++itL) if (itL->second == i) { if (stPos == -1) { HT::const_iterator itR = rightExp.cbegin(); for (; itR != rightExp.cend() && itR->second != 0; ++itR); if (itR->first == itL->first) curPos = stPos = itL->second; } else for (HT::const_iterator itR = rightExp.cbegin(); itR != rightExp.cend(); ++itR) if (itR->first == itL->first) { if (itL->second > curPos && itL->second - curPos == 1) { curPos = itL->second; } } if ((curPos - stPos +1) == sizeR) break; if (curPos != itL->second) stPos = -1; } } if(stPos!=-1) erase(leftExp, stPos, stPos + rightExp.size()-1); else return 1; } return 0; }
/** Finds an element in the set. * * @param item the item to look for * * @return a #const_iterator pointing to the item, or @p end() if the * item cannot be found in the set. */ iterator find( const value_type& item ) const { return m_ht.find( item ); }
/** Erases the element identified by the key. * * @param key The key of the item to be deleted. * * @return The number of deleted item. Since the item in cache_set are * unique, this will either be 1 when the key is found and 0 when no * item is deleted. */ size_type erase( const key_type& key ) { return m_ht.erase( key ); }
/** 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; }
void insert( InputIterator first, InputIterator last ) { m_ht.insert( first, last ); }
/** 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 ); }
/** Get the value of the empty item. * * @return the item value used to mark empty buckets. */ const value_type& get_empty_key() const { return m_ht.get_empty_value(); }
/** Sets the value of the empty key. * * @param value the value value that will be used to identify empty items. */ void set_empty_key( const value_type& value ) { m_ht.set_empty_value( value ); }
/** Erases all elements in a range. * * The range of elements to be deleted will be @p [first,last) * * @param first The first element in the range (included) * @param last The last element in the range (excluded) */ void erase( iterator first, iterator last ) { m_ht.erase( first, last ); }
/** Removes all the elements. */ void clear() { m_ht.clear(); }
cache_set( InputIterator first, InputIterator last ) : m_ht( 2 * std::distance( first, last ) ) { m_ht.insert( first, last ); }
/** Increases the bucket count to at least @a size. * * @param size the new maximum number of elements. * * @warning This operation can be particularly time-consuming. The * algorithm is O(n) and can leave to the complete re-hash of all * of the elements in the cache_set. */ void resize( size_type size ) { m_ht.resize( size ); }
/** Erases the element pointed to by the iterator. * * @param it a valid iterator to an element in cache_set. */ void erase( iterator it ) { m_ht.erase( it ); }
cache_set( InputIterator first, InputIterator last, size_type n ) : m_ht( 2 * n ) { m_ht.insert( first, last ); }