void checkOAHash_aux (size_t maxMemory) { /** We create a hash with a maximum memory size. */ OAHash <T> hash (maxMemory); T badKey; badKey.setVal(hash.getMaxNbItems() + 100); /** We insert the maximum number of items. */ for (int i=1; i<=hash.getMaxNbItems(); i++) { T idx; idx.setVal(i); CPPUNIT_ASSERT_NO_THROW (hash.increment (idx)); } /** We add a new key => we should get an exception. */ CPPUNIT_ASSERT_THROW (hash.increment (badKey), core::system::Exception); /** We check that we have all the required keys. */ for (int i=1; i<=hash.getMaxNbItems(); i++) { T idx; idx.setVal(i); CPPUNIT_ASSERT (hash.get (idx) == true); } /** We check that we don't have an non registered key. */ CPPUNIT_ASSERT (hash.get (badKey) == false); /** We iterate the map. */ Iterator <Abundance<T> >* it = hash.iterator(); LOCAL (it); size_t nbItems = 0; for (it->first(); !it->isDone(); it->next(), nbItems++) { /** All abundances should be one. */ CPPUNIT_ASSERT (it->item().abundance == 1); } CPPUNIT_ASSERT ((int)nbItems == hash.getMaxNbItems()); }
void test_reverse_remove__last(List<int> &list) { printf("test_reverse_remove__last\n"); for(int i=0; i < 10; i++) { list.add(i*i); } Iterator<int> iterator = list.reverse(); for(int i=9;i>0;i--) { iterator.next(); } iterator.remove(); if(list.size() != 9) { printf("test_reverse_remove__last wrong list size %d should be 9\n", list.size()); } for(int i=1; i<10;i++) { if(list[i-1] != i*i) { printf("test_reverse_remove__last wrong value should be %d found %d\n", i*i, list[i-1]); } } }
VarTree::Iterator VarTree::getLeaf( int n ) { Iterator it = m_children.begin(); while( it != m_children.end() ) { if( it->size() ) { int i; i = n - it->countLeafs(); if( i <= 0 ) return it->getLeaf( n ); n = i; } else { n--; if( n <= 0 ) return it; } ++it; } return m_children.end(); }
inline bool check_outside_range( const Iterator& it,const Iterator& it0,const Iterator& it1) { if(!check_same_owner(it0,it1))return false; if(it0.valid()){ Iterator last=it0.owner()->end(); bool found=false; Iterator first=it0; for(;first!=last;++first){ if(first==it1)break; /* crucial that this check goes after previous break */ if(first==it)found=true; } if(first!=it1)return false; return !found; } return true; }
void CommunitySpace::initialize( int level) { int i; total_weight = 0; Iterator<node>* nodes = theGraph->getNodes(); int n_edges = theGraph->numberOfEdges(); //int start_time = clock(); while (nodes->hasNext()) { node n = nodes->next(); groups[n.id] = n.id; total[n.id] = theGraph->deg(n)/2; incoming[n.id] = getSelfLoops(n); } delete nodes; if (weights == NULL) { total_weight = n_edges; } else { for (i = 0; i < n_edges; i++) { total_weight += weights[i]; } } //cout << "Graph initilized with: " << theGraph->numberOfNodes() << " nodes, "<< n_edges << " edges and " << total_weight << " total weight in " << ((clock()-start_time)/(float)CLOCKS_PER_SEC) << " seconds." << endl; }
int main (int argc, char* argv[]) { // We load a Storage product "foo" in HDF5 format // It must have been created with the storage1 snippet //! [snippet1_storage] Storage* storage = StorageFactory(STORAGE_HDF5).load ("foo"); //! [snippet1_storage] LOCAL (storage); // Shortcut: we get the root of this Storage object Group& root = storage->root(); // We get a collection of native integer from the storage. Collection<NativeInt64>& myIntegers = root.getCollection<NativeInt64> ("myIntegers"); // We create an iterator for our collection. Iterator<NativeInt64>* iter = myIntegers.iterator(); LOCAL (iter); // Now we can iterate the collection through this iterator. for (iter->first(); !iter->isDone(); iter->next()) { cout << iter->item() << endl; } }
//========================================================================= void GraphAbstract::delSubGraph(Graph *toRemove) { // look for the graph we want to remove in the subgraphs GRAPH_SEQ::iterator it = std::find(subgraphs.begin(), subgraphs.end(), toRemove); assert(it != subgraphs.end()); if (it != subgraphs.end()) { subGraphToKeep = NULL; // remove from subgraphs notifyBeforeDelSubGraph(toRemove); subgraphs.erase(it); Iterator<Graph *> *itS = toRemove->getSubGraphs(); // add toRemove subgraphs while (itS->hasNext()) { restoreSubGraph(itS->next()); } delete itS; notifyAfterDelSubGraph(toRemove); // subGraphToKeep may have change on notifyDelSubGraph // see GraphUpdatesRecorder::delSubGraph // in GraphUpdatesRecorder.cpp if (toRemove != subGraphToKeep) { // avoid deletion of toRemove subgraphs toRemove->clearSubGraphs(); delete toRemove; } else // toRemove is not deleted, // and its subgraphs list is not erased; // beacause it is registered into a GraphUpdatesRecorder // in order it can be restored on undo or redo toRemove->notifyDestroy(); } }
Bag *Bag::Intersect(Bag* other) const { assert(other != nullptr); Bag *result = new Bag(); Iterator *it = NewIterator(); for(Object *o = it->Next(); o != nullptr;o = it->Next()) { if(other->Contains(o)) { // other bag contains o //Object not already in result bag if(!result->Contains(o)) { BagNode *thisBagNode = Find(o); BagNode *otherBagNode = other->Find(o); int count = min(thisBagNode->count, otherBagNode->count); for(int i = 0; i < count; i++){ result->Add(o); } } } } delete it; return result; }
inline void detach_equivalent_iterators(Iterator& it) { if(it.valid()){ { #if defined(BOOST_HAS_THREADS) geofeatures_boost::detail::lightweight_mutex::scoped_lock lock(it.cont->mutex); #endif Iterator *prev_,*next_; for( prev_=static_cast<Iterator*>(&it.cont->header); (next_=static_cast<Iterator*>(prev_->next))!=0;){ if(next_!=&it&&*next_==it){ prev_->next=next_->next; next_->cont=0; } else prev_=next_; } } it.detach(); } }
/** * @brief * Returns a list of all visible scene node instances intersecting with the given scene node, recursive part */ void SRPVolume::GetIntersectingInstancesOfRec(const SQCull &cCullQuery, SceneNode &cSceneNode, const Class &cClass, Array<const VisNode*> &lstIntersecting) const { // Get visibility container const VisContainer &cVisContainer = cCullQuery.GetVisContainer(); // Search through all visible scene nodes of this scene container Iterator<VisNode*> cIterator = cVisContainer.GetVisNodes().GetIterator(); while (cIterator.HasNext()) { // Get visibility node and scene node const VisNode *pVisNode = cIterator.Next(); SceneNode *pSceneNode = pVisNode->GetSceneNode(); if (pSceneNode) { // Is this scene node a portal? if (pVisNode->IsPortal()) { // Get the target cell visibility container const VisContainer *pVisCell = static_cast<const VisPortal*>(pVisNode)->GetTargetVisContainer(); if (pVisCell && pVisCell->GetCullQuery()) { // Search within the target cell GetIntersectingInstancesOfRec(*pVisCell->GetCullQuery(), cSceneNode, cClass, lstIntersecting); } // Is this scene node a container? We do not need to check for cells because we will // NEVER receive cells from SQCull directly, they are ONLY visible through portals! (see above) } else if (pVisNode->IsContainer()) { // Search within this container without special processing if (static_cast<const VisContainer*>(pVisNode)->GetCullQuery()) GetIntersectingInstancesOfRec(*static_cast<const VisContainer*>(pVisNode)->GetCullQuery(), cSceneNode, cClass, lstIntersecting); // This must just be a quite boring scene node :) } else { // Is this a directional light scene node? if (pSceneNode->IsInstanceOfByReference(cClass)) { // [TODO] Intersection test lstIntersecting.Add(pVisNode); } } } } }
//---------------------------------------------------------------------------------------------- int ObjectSerializer::SerializeUserDefinedType(ISerializable *pObj, TypeNode* pType, bool isPtr, fstream& pen) { int size = 0; bool isNull = false; if (isPtr) { // Access the pointer pointed by the pointer to pointer pObj = (*(ISerializable**)pObj); int length = 0; string typeName; char buffer[MaxTypeNameLength + 1]; isNull = (NULL == pObj); pen.write(reinterpret_cast<char*>(&isNull), sizeof(bool)); if (!isNull) { auto objLayout = pObj->GetObjectLayout(); typeName = g_ObjectFactory.FromCName(objLayout.CName()); PerformLateBinding(pObj, pType); length = typeName.size(); _ASSERTE(length <= MaxTypeNameLength); strcpy_s(buffer, typeName.c_str()); buffer[length] = 0; pen.write(buffer, MaxTypeNameLength + 1); Iterator* addresses = objLayout.GetIterator(); unsigned* addr32; for (int memberIdx = 0; addresses->MoveNext(); ++memberIdx) { _ASSERTE(memberIdx < pType->Children.size()); addr32 = reinterpret_cast<unsigned*>(addresses->Current()); SerializeType(reinterpret_cast<char*>(*addr32), pType->Children[memberIdx].Ptr32, pen); } } size = sizeof(unsigned); } else { auto objLayout = pObj->GetObjectLayout(); Iterator* addresses = objLayout.GetIterator(); unsigned* addr32; for (int memberIdx = 0; addresses->MoveNext(); ++memberIdx) { _ASSERTE(memberIdx < pType->Children.size()); addr32 = reinterpret_cast<unsigned*>(addresses->Current()); SerializeType(reinterpret_cast<char*>(*addr32), pType->Children[memberIdx].Ptr32, pen); } size = objLayout.TypeSize(); } return size; }
/* * Returns in sortedNodes the nodes n of g sorted in increasing * order by value[n]. * Precondition: * - value[n] <= numberOfNodes for all nodes n of g, where n is * the number of * nodes in g */ void PlanarityTestImpl::sortNodesIncreasingOrder(Graph *g, MutableContainer<int> &value, vector<node> &sortedNodes) { // Counting sort; int numberOfNodes = g->numberOfNodes(); //array<int, numberOfNodes + 1> c; vector<int> c(numberOfNodes + 1); for (int i = 1 ; i <= numberOfNodes ; i++) c[i] = 0; //array<node, numberOfNodes + 1> a; vector<node> a(numberOfNodes + 1); int j = 0; node n; // forall_nodes(n, g) Iterator<node> *it = g->getNodes(); while (it->hasNext()) { //a[++j] = n; a[++j] = it->next(); } delete it; for (int i = 1 ; i <= numberOfNodes ; i++) { unsigned int tmp = value.get(a[i].id); c[tmp]++; } for (int i = 2 ; i <= numberOfNodes ; i++) c[i] += c[i-1]; for (int i = numberOfNodes ; i > 0 ; i--) { sortedNodes[c[value.get(a[i].id)]] = a[i]; c[value.get(a[i].id)]--; } }
int main(int argc, char*argv[]) { std::ifstream in((argc>1)?argv[1]:"data/triangles.xyz"); Triangles triangles; Triangle_3 t; while(in >> t){ triangles.push_back(t); } // Create the corresponding vector of bounding boxes std::vector<Box> boxes; for ( Iterator i = triangles.begin(); i != triangles.end(); ++i) boxes.push_back( Box( i->bbox(), i)); // Create the corresponding vector of pointers to bounding boxes std::vector<Box *> ptr; for ( std::vector<Box>::iterator i = boxes.begin(); i != boxes.end(); ++i) ptr.push_back( &*i); // Run the self intersection algorithm with all defaults on the // indirect pointers to bounding boxes. Avoids copying the boxes. CGAL::box_self_intersection_d( ptr.begin(), ptr.end(), Report(triangles)); return 0; }
GlGraphComposite::GlGraphComposite(Graph* graph, GlScene *scene):inputData(graph,¶meters),nodesModified(true) { this->graphRenderer=new GlGraphHighDetailsRenderer(&inputData,scene); if(!graph) { rootGraph=NULL; } else { rootGraph=graph->getRoot(); graph->addListener(this); graph->getRoot()->getProperty<GraphProperty>("viewMetaGraph")->addListener(this); Iterator<node>* nodesIterator = graph->getNodes(); while (nodesIterator->hasNext()) { node n=nodesIterator->next(); if(graph->getNodeMetaInfo(n)) metaNodes.insert(n); } delete nodesIterator; } }
int main() { Array<int> v; for (int i = 0; i < 20; i++) { v.add(i); } v[1] = 9999; cout << v << endl; const Array<int> cv = static_cast<const Array<int> >(v); cout << cv[10] << endl; v.removeAt(9); cout << v << endl; Iterator<int> it = v.iter(); while (it.isValid()) { cout << it.get() << endl; if (rand() % 4 < 1) { it.remove(); } it.next(); } return 0; }
ControllerDescription readController(Element &controllerElem) { //Check for illegal nodes here Iterator< Node > c; for ( c = c.begin(&controllerElem); c != c.end(); c++ ) { if(c->Type() == TiXmlNode::ELEMENT) { string s = c->Value(); LOG(LFATAL) << "Illegal element in xml file: " << s; throw XmlParsingException("Illegal element in xml file: " + s); } } ControllerDescription theController; //Parse the component type theController.type = controllerElem.GetAttribute("class"); boost::to_lower(theController.type); LOG(LINFO) << "Parsed controller: " << theController.type; return theController; }
void SaveAsFasta (IBank* bank, const std::string& uri) { BankFasta output (uri); Iterator<Sequence>* it = bank->iterator(); LOCAL (it); std::stringstream ss; size_t count=0; for (it->first(); !it->isDone(); it->next()) { // Shortcut. Sequence& seq = it->item(); // We define some decent header ss.str (""); ss << count++ << "__len__" << seq.getDataSize(); seq.setComment (ss.str()); output.insert (seq); } }
size_t RingBuffer::trim( byte *start, byte *end, byte symbol ) { size_t newSize=0; byte *data_ptr; Iterator *it; if( (start == NULL) || (end == 0) ) return 0; size_t index_start = indexOf(start); it = iterator( start, end ); while( (data_ptr = it->next()) ){ if(*data_ptr == symbol) data_ptr = it->next(); data[(index_start+newSize)%BUFFER_SIZE] = *data_ptr; newSize++; } return newSize; }
Object LoggerContextExtensionI::extend(Object object) throw (Exception) { Logger logger; object->downcast(logger); //cout << "logger:" << logger->getName() << endl; InitialContext initialcontext = InitialContext::newInstance(); Iterator<MapEntry<String, Object> > i = initialcontext->listBindings(L"/")->entrySet()->iterator(); while (i->hasNext()) { MapEntry<String, Object> current = i->next(); StringAnything any; if (current->value->instanceOf(any)) { if (any->toString()->toLowerCase() == logger->getName()) { StringBuffer buf = current->key; initialcontext->lookup(buf->substring(0, buf->lastIndexOf(L"/name")), logger); //cout << "loggerconfig:" << buf->substring(0, buf->lastIndexOf(L"/name")) << endl; break; } } } return logger; }
void ChannelList::channelsWithPrefix (const char prefix[], Iterator &first, Iterator &last) { first = last = _map.lower_bound (prefix); int n = strlen (prefix); while (last != Iterator (_map.end()) && strncmp (last.name(), prefix, n) <= 0) { ++last; } }
status_t BNetworkCookieJar::Archive(BMessage* into, bool deep) const { status_t error = BArchivable::Archive(into, deep); if (error == B_OK) { const BNetworkCookie* cookiePtr; for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) { BMessage subArchive; error = cookiePtr->Archive(&subArchive, deep); if (error != B_OK) return error; error = into->AddMessage(kArchivedCookieMessageName, &subArchive); if (error != B_OK) return error; } } return error; }
SequenceableCollection* const SequenceableCollection::allButLast(int n) const { SequenceableCollection* ret; Iterator* it; int i = 0; int ret_size = ret->size(); if ( n < 0 || (n + 1) > len ) argumentBeyondRange( "n", n ); ret = __REINTERPRET_CAST(SequenceableCollection *, copyEmpty( size() - (n + 1) ) ); for ( it = iterator(); it->finished(); it->next() ) { if ( i >= ret_size ) break; ret->put( i ++, it->current() ); } delete it; return ret; }
int ClientNetMessage::make_packet(char *buff, int size) { int pos = 0, key_len, val_len, len; for(Iterator i = start(); i.has_val() && pos < size; i.next()) { KeyValue v = i.val(); key_len = strlen(v.first.text); val_len = strlen(v.second.text); len = key_len + val_len + 2; if(size - pos - len > 0) { mir_snprintf(buff + pos, size - pos, "\\%s\\%s", v.first.text, v.second.text); pos += len; } else return -1; } if(size - pos > 7) { mir_snprintf(buff + pos, size - pos, "\\final\\"); pos += 7; return pos; } return -1; }
// Transfers solution from the coarse mesh to the reference one. The // solution will remain identical, but a new coefficient vector // y_prev_ref will be constructed/ // WARNING: For this to work, element DOF must be assigned correctly // in both the coarse and fine meshes! void transfer_solution_forward(Space *space, Space *space_ref) { Iterator *I = new Iterator(space); Iterator *I_ref = new Iterator(space_ref); // simultaneous traversal of 'space' and 'space_ref' Element *e, *e_ref, *e_ref_left, *e_ref_right; for (int comp=0; comp < space->get_n_eq(); comp++) { I->reset(); I_ref->reset(); while ((e = I->next_active_element()) != NULL) { e_ref = I_ref->next_active_element(); if (e->level == e_ref->level) transform_element_unrefined_forward(comp, e, e_ref); else { e_ref_left = e_ref; e_ref_right = I_ref->next_active_element(); transform_element_refined_forward(comp, e, e_ref_left, e_ref_right); } } } }
void test_getNext_function_properly_through_iterator() { LinkedList *testList = createLinkedList(); Iterator *iter; Element elem[1000]; int i; for(i=0;i<1000;i++) { List_Add(&elem[i],testList); } //testElement = testList->head; iter = getIterator(testList); for(i=0;i<1000;i++) { TEST_ASSERT_EQUAL(&elem[i],iter->current); iter->current = iter->next(iter->current); } TEST_ASSERT_EQUAL(NULL,iter->current); List_DestroyList(testList); destroyIterator(iter); }
void Player::Sort(int th){ Iterator<Card> cur = card.begin(); Iterator<Card> next = cur; ++next; while (cur != card.end() && next != card.end()){ if ((*cur).type != th && (*next).type == th || (*cur).type == th && (*next).type == th && (*cur).value > (*next).value || (*cur).type != th && (*next).type != th && (*cur).value > (*next).value){ Card tmp = *cur; cur.SetInfo(*next); next.SetInfo(tmp); cur = card.begin(); next = card.begin(); ++next; } else{ ++cur; ++next; } } }
bool FreeLosslessAudioCodecFileMetadata::ReadFileProperties(QString fileName) { Chain chain; Iterator iterator; properties.clear(); if(chain.is_valid() && iterator.is_valid()) { if(chain.read(fileName.toLatin1(), false)) { do { if(iterator.get_block_type() == FLAC__METADATA_TYPE_VORBIS_COMMENT) { VorbisComment* comment = dynamic_cast<VorbisComment*>(iterator.get_block()); for(unsigned int i(0); i<comment->get_num_comments(); ++i) { VorbisComment::Entry entry = comment->get_comment(i); properties[entry.get_field_name()] += QString(entry.get_field_value()); } } } while(iterator.next()); } return(true); } return(false); }
static PQueue *Copy(const PQueue *src) { PQueue *result; Iterator *it; int r; PQueueElement *obj; if (src == NULL) return NULL; result = CreateWithAllocator(src->ElementSize,src->Allocator); if (result == NULL) return NULL; it = iHeap.NewIterator(src->Heap); for (obj = it->GetFirst(it); obj != NULL; obj = it->GetNext(it)) { if (obj->Key != INT_MIN) { r = Add(result,obj->Key,obj->Data); if (r < 0) { Finalize(result); return NULL; } } } iHeap.deleteIterator(it); return result; }
int SSDB::hlist(const Bytes &name_s, const Bytes &name_e, int limit, std::vector<std::string> *list) const{ std::string start; std::string end; start = encode_hsize_key(name_s); if(!end.empty()){ end = encode_hsize_key(name_e); } Iterator *it = this->iterator(start, end, limit); while(it->next()){ Bytes ks = it->key(); if(ks.data()[0] != DataType::HSIZE){ break; } std::string n; if(decode_hsize_key(ks, &n) == -1){ continue; } list->push_back(n); } delete it; return 0; }
int Ardb::LastDB(DBID& db) { int ret = -1; Iterator* iter = NewIterator(ARDB_GLOBAL_DB); if (NULL != iter && iter->Valid()) { //Skip last KEY_END entry iter->Prev(); } if (NULL != iter && iter->Valid()) { Slice tmpkey = iter->Key(); KeyObject* kk = decode_key(tmpkey, NULL); if (NULL != kk) { db = kk->db; ret = 0; } DELETE(kk); } DELETE(iter); return ret; }