static inline void cleanPath(Vector<UChar, 512>& path) { // FIXME: Should not do this in the query or anchor part. int pos; while ((pos = findSlashDotDotSlash(path.data(), path.size())) != -1) { int prev = reverseFind(path.data(), path.size(), '/', pos - 1); // don't remove the host, i.e. http://foo.org/../foo.html if (prev < 0 || (prev > 3 && path[prev - 2] == ':' && path[prev - 1] == '/')) path.remove(pos, 3); else path.remove(prev, pos - prev + 3); } // FIXME: Should not do this in the query part. // Set refPos to -2 to mean "I haven't looked for the anchor yet". // We don't want to waste a function call on the search for the the anchor // in the vast majority of cases where there is no "//" in the path. pos = 0; int refPos = -2; while ((pos = findSlashSlash(path.data(), path.size(), pos)) != -1) { if (refPos == -2) refPos = find(path.data(), path.size(), '#'); if (refPos > 0 && pos >= refPos) break; if (pos == 0 || path[pos - 1] != ':') path.remove(pos); else pos += 2; } // FIXME: Should not do this in the query or anchor part. while ((pos = findSlashDotSlash(path.data(), path.size())) != -1) path.remove(pos, 2); }
static inline void cleanPath(Vector<UChar, 512>& path) { // FIXME: Should not do this in the query or anchor part. size_t pos; while ((pos = findSlashDotDotSlash(path.data(), path.size())) != notFound) { size_t prev = reverseFind(path.data(), path.size(), '/', pos - 1); // don't remove the host, i.e. http://foo.org/../foo.html if (prev == notFound || (prev > 3 && path[prev - 2] == ':' && path[prev - 1] == '/')) path.remove(pos, 3); else path.remove(prev, pos - prev + 3); } // FIXME: Should not do this in the query part. pos = 0; if ((pos = findSlashSlash(path.data(), path.size(), pos)) != notFound) { size_t refPos = find(path.data(), path.size(), '#'); while (refPos == 0 || refPos == notFound || pos < refPos) { if (pos == 0 || path[pos - 1] != ':') path.remove(pos); else pos += 2; if ((pos = findSlashSlash(path.data(), path.size(), pos)) == notFound) break; } } // FIXME: Should not do this in the query or anchor part. while ((pos = findSlashDotSlash(path.data(), path.size())) != notFound) path.remove(pos, 2); }
bool formsDominoChain(Vector<Domino> &dominos, Vector<Domino> toBeSorted, Vector<Domino> &solution) { if (solution.size() >= dominos.size() && isValidChain(solution)) { cout << solution << endl; return true; } for (int i = 0; i < toBeSorted.size(); i++) { for (int j = 0; j < 2; j++) { Vector<Domino> tester; tester += solution[solution.size() - 1]; tester += toBeSorted[i]; if (j == 0 && isValidChain(tester)) { solution += toBeSorted[i]; if (formsDominoChain(dominos, subtract(dominos, solution), solution)) { return true; } solution.remove(solution.size() - 1); } tester.clear(); tester += solution[solution.size() - 1]; tester += toBeSorted[i]; tester[tester.size() - 1].flip(); if (j == 1 && isValidChain(tester)) { solution += toBeSorted[i]; Vector<Domino> flippedSolution = solution; flippedSolution[flippedSolution.size() - 1].flip(); if (formsDominoChain(dominos, subtract(dominos, solution), flippedSolution)) { return true; } solution.remove(solution.size() - 1); } } } return false; }
void test_add_remove_torture() { int width = gw->getCanvasWidth(); int height = gw->getCanvasHeight(); int numEachObj = 100; Vector<GObject *> objs; Vector<GObject *> added; for (int i = 0; i<numEachObj; i++) { int x = randomInteger(0, width); int y = randomInteger(0, height); int w = randomInteger(1, width/2); int h = randomInteger(1, width/2); GRect *r = new GRect(x, y, w, h); r->setLineWidth(2); r->setColor(colors[randomInteger(0, 12)]); r->rotate(randomReal(0,90)); objs.add(r); } for (int i = 0; i < 2000; i++) { if (randomChance(0.8)) { int index = randomInteger(0, objs.size() - 1); gw->add(objs[index]); added.add(objs[index]); } pause(1); if (randomChance(0.05) && !added.isEmpty()) { int index = randomInteger(0, added.size() - 1); gw->remove(added[index]); added.remove(index); } pause(1); } }
void grow(Vector<char> & seq, int lo, int hi) { int length = seq.size(); if (lo == -1 || hi == length || seq[lo] != seq[hi]) seq.remove(lo + 1, hi); else { int oldLo = lo; int oldHi = hi; char letter = seq[lo]; int counter = 0; while (lo > -1 && seq[lo] == letter) {lo--; counter++;} while (hi < length && seq[hi] == letter) {hi++; counter++;} if (counter < 3) seq.remove(oldLo + 1, oldHi); else grow(seq, lo, hi); } return; }
bool RecursiveCutStock(Vector<int>& requests, int stock_length, int number_of_stock, int remaning_length) { //Success case, solution found if(requests.size() == 0) return true; if(number_of_stock < 1) //run out of stocks return false; for (int i = 0; i < requests.size(); ++i) { int requested_stock = requests[i]; while(remaning_length < requested_stock) { number_of_stock--; remaning_length = stock_length; if(number_of_stock < 1) //run out of stocks return false; } remaning_length -= requested_stock; //apply configuration requests.remove(i); if(RecursiveCutStock(requests, stock_length, number_of_stock, remaning_length)) return true; remaning_length += requested_stock; //revert the configuration requests.add(requested_stock); } return false; //Return false to proceed the backtrack }
/* * Function: depthFirstSearchHelper * -------------------- * This function implements the recursive backtracking for the DFS algorithm * * Preconditions: * * @param: graph: The graph to be searched * start: The start vertex * end:The end vertex * path: a reference to the vector of vertexes to store the path * @return: returns nothing */ void depthFirstSearchHelper(BasicGraph& graph, Vertex* start, Vertex* end,Vector<Vertex*>& path) { // Add v1 to path path.add(start); start->setColor(GREEN); // Mark v1 as visited start->visited = true; // If v1 is v2, a path is found if(start == end){ return; } // For each unvisited neighbor of start vertex for (Vertex* n: graph.getNeighbors(start)){ // And it's unvisited if(n->visited == false){ depthFirstSearchHelper(graph,n,end,path); if(path[path.size()-1] == end){ return; } } } // Unchoose Vertex* toRemove = path[path.size()-1]; toRemove->setColor(GRAY); // If we get here, no path was found with start path.remove(path.size()-1); }
void ScenesDock::_favorites_pressed() { TreeItem *sel = tree->get_selected(); if (!sel) return ; String dir = sel->get_metadata(0); int idx = -1; Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs(); for(int i=0;i<favorites.size();i++) { if (favorites[i]==dir) { idx=i; break; } } if (button_favorite->is_pressed() && idx==-1) { favorites.push_back(dir); EditorSettings::get_singleton()->set_favorite_dirs(favorites); _update_tree(); } else if (!button_favorite->is_pressed() && idx!=-1) { favorites.remove(idx); EditorSettings::get_singleton()->set_favorite_dirs(favorites); _update_tree(); } }
bool MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack) { // This is a common part used by removeTrack called by JavaScript // and removeRemoteTrack and only removeRemoteTrack must fire removetrack event RefPtr<MediaStreamTrack> track = prpTrack; Vector<RefPtr<MediaStreamTrack>>* tracks = trackVectorForType(track->source()->type()); size_t pos = tracks->find(track); if (pos == notFound) return false; tracks->remove(pos); m_private->removeTrack(&track->privateTrack()); // There can be other tracks using the same source in the same MediaStream, // like when MediaStreamTrack::clone() is called, for instance. // Spec says that a source can be shared, so we must assure that there is no // other track using it. if (!haveTrackWithSource(track->source())) m_private->removeSource(track->source()); track->removeObserver(this); if (!m_audioTracks.size() && !m_videoTracks.size()) setActive(false); return true; }
void WebCL::cacheSupportedExtensions() { if (!m_platforms.size()) return; Vector<String> supportedExtensions = m_platforms[0]->getSupportedExtensions(); if (m_platforms.size() == 1) { // If there is only one platform, WebCL extensions is equal to this platform's extension. return; } for (auto platform : m_platforms) { Vector<String> temporary = platform->getSupportedExtensions(); Vector<String> toBeRemoved; for (auto supportedExtension : supportedExtensions) { Vector<String>::iterator iter = temporary.begin(); for (; iter != temporary.end(); ++iter) { if (supportedExtension == *iter) break; } if (iter == temporary.end()) toBeRemoved.append(supportedExtension); } for (auto stringToBeRemoved : toBeRemoved) supportedExtensions.remove(supportedExtensions.find(stringToBeRemoved)); } for (auto supportedExtension : supportedExtensions) m_extension.addSupportedCLExtension(supportedExtension); }
/** * Retrieving end result. Calculating elements of queue * @param postfixNotat - Queue of operators and operands in postfix notation * @return - Result of user's expression */ double processingQueueOfPostfixNotation(Queue<string> postfixNotat) { double res; Vector<string> vec; while(!postfixNotat.isEmpty()) { vec.add(postfixNotat.dequeue()); } for(int i = 0; i < vec.size(); i++) { if(vec.size() == 1) { break; } string tmp = vec[i]; if(isOperator(tmp[0]) && i >= 2) { string tok = vec[i]; double secondOperand = atof(vec[i-1].c_str()); double firstOperand = atof(vec[i-2].c_str()); double calcResult = executeOperation(firstOperand,secondOperand,tok[0]); string r2 = to_string(calcResult); vec.set(i-2, r2); vec.remove(i-1); vec.remove(i-1); i = 0; } } return res = atof(vec[0].c_str()); }
Vector<String> ResourceSpawnImplementation::getSpawnZones(int minpool, int maxpool, const String& zonerestriction, Vector<String>& activeZones) { /** * Here we are using defined rules to set the number * of zones and specific zones of this specific spawn */ Vector<String> zonenames; int zonecount = 0; if(minpool == maxpool) zonecount = maxpool; else zonecount = System::random(maxpool - minpool) + minpool; if(zonecount > activeZones.size()) zonecount = activeZones.size(); /// If resource is zone restricted, add only the restricted zone if (zonerestriction != "") { zonenames.add(zonerestriction); return zonenames; } /// Randomly remove entries until the Vector contains /// a number of elements equal to zonecount while (activeZones.size() > zonecount) activeZones.remove(System::random(activeZones.size() - 1)); return activeZones; }
void WebPlatformStrategies::getWebVisiblePluginInfo(const Page* page, Vector<PluginInfo>& plugins) { ASSERT_ARG(page, page); ASSERT_ARG(plugins, plugins.isEmpty()); getPluginInfo(page, plugins); #if PLATFORM(MAC) if (Document* document = page->mainFrame().document()) { if (SecurityOrigin* securityOrigin = document->securityOrigin()) { if (securityOrigin->isLocal()) return; } } for (int32_t i = plugins.size() - 1; i >= 0; --i) { PluginInfo& info = plugins.at(i); PluginLoadClientPolicy clientPolicy = info.clientLoadPolicy; // Allow built-in plugins. Also tentatively allow plugins that the client might later selectively permit. if (info.isApplicationPlugin || clientPolicy == PluginLoadClientPolicyAsk) continue; if (clientPolicy == PluginLoadClientPolicyBlock) plugins.remove(i); } #endif }
void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins) { ASSERT_ARG(plugins, plugins.isEmpty()); getPluginInfo(page, plugins); #if PLATFORM(MAC) if (auto* document = page.mainFrame().document()) { if (auto* securityOrigin = document->securityOrigin()) { if (securityOrigin->isLocal()) return; } } for (int32_t i = plugins.size() - 1; i >= 0; --i) { auto& info = plugins.at(i); // Allow built-in plugins. Also tentatively allow plugins that the client might later selectively permit. if (info.isApplicationPlugin || info.clientLoadPolicy == WebCore::PluginLoadClientPolicyAsk) continue; if (info.clientLoadPolicy == WebCore::PluginLoadClientPolicyBlock) plugins.remove(i); } #endif }
void GeolocationClientBlackBerry::cancelPermissionRequest(Geolocation* location) { Frame* frame = location->frame(); if (!frame) return; const String origin = frame->document()->securityOrigin()->toString(); // Remove the geolocation from the pending permission map. HashMap<String, Vector<RefPtr<Geolocation> > >::iterator it = m_geolocationRequestMap.find(origin); ASSERT(it != m_geolocationRequestMap.end()); if (it == m_geolocationRequestMap.end()) return; Vector<RefPtr<Geolocation> >* result = &(it->value); size_t geolocationCount = result->size(); for (size_t i = 0; i < geolocationCount; ++i) { if ((*result)[i].get() == location) { result->remove(i); // Remove this vector from the pending permission map is it doesn't contain anymore geo objects if (result->isEmpty()) m_geolocationRequestMap.remove(origin); break; } } if (m_geolocationRequestMap.isEmpty()) BlackBerry::Platform::GeolocationHandler::instance()->unregisterFromPermissionTracking(this); m_webPagePrivate->m_client->cancelGeolocationPermission(); }
static inline void clearTimesWithDynamicOrigins(Vector<SMILTimeWithOrigin>& timeList) { for (int i = timeList.size() - 1; i >= 0; --i) { if (timeList[i].originIsScript()) timeList.remove(i); } }
void TextTrackList::remove(TrackBase& track, bool scheduleEvent) { auto& textTrack = downcast<TextTrack>(track); Vector<RefPtr<TrackBase>>* tracks = nullptr; switch (textTrack.trackType()) { case TextTrack::TrackElement: tracks = &m_elementTracks; break; case TextTrack::AddTrack: tracks = &m_addTrackTracks; break; case TextTrack::InBand: tracks = &m_inbandTracks; break; default: ASSERT_NOT_REACHED(); } size_t index = tracks->find(&track); if (index == notFound) return; invalidateTrackIndexesAfterTrack(textTrack); ASSERT(!track.mediaElement() || !element() || track.mediaElement() == element()); track.setMediaElement(nullptr); Ref<TrackBase> trackRef = *(*tracks)[index]; tracks->remove(index); if (scheduleEvent) scheduleRemoveTrackEvent(WTFMove(trackRef)); }
void EditorFileDialog::_save_to_recent() { String dir = get_current_dir(); Vector<String> recent = EditorSettings::get_singleton()->get_recent_dirs(); const int max=20; int count=0; bool res=dir.begins_with("res://"); for(int i=0;i<recent.size();i++) { bool cres=recent[i].begins_with("res://"); if (recent[i]==dir || (res==cres && count>max)) { recent.remove(i); i--; } else { count++; } } recent.insert(0,dir); EditorSettings::get_singleton()->set_recent_dirs(recent); }
void TextTrackList::remove(TextTrack* track) { Vector<RefPtr<TextTrack> >* tracks = 0; RefPtr<InbandTextTrack> inbandTrack; if (track->trackType() == TextTrack::TrackElement) { tracks = &m_elementTracks; } else if (track->trackType() == TextTrack::AddTrack) { tracks = &m_addTrackTracks; } else if (track->trackType() == TextTrack::InBand) { tracks = &m_inbandTracks; inbandTrack = static_cast<InbandTextTrack*>(track); } else { ASSERT_NOT_REACHED(); } size_t index = tracks->find(track); if (index == kNotFound) return; invalidateTrackIndexesAfterTrack(track); ASSERT(track->mediaElement() == m_owner); track->setMediaElement(0); tracks->remove(index); if (inbandTrack) inbandTrack->trackRemoved(); }
bool solvePuzzle(Grid<MarbleType>& board, int marblesLeft, Set<uint32_t>& exploredBoards, Vector<Move>& moveHistory){ /* TODO: COMPLETE THIS */ if (exploredBoards.size()%10000 == 0){ cout << "Boards evaluated: " << exploredBoards.size() << "\tDepth: " << moveHistory.size() << endl; cout.flush(); } if(marblesLeft == 1) return true; if(exploredBoards.contains(compressMarbleBoard(board))) return false; exploredBoards.add(compressMarbleBoard(board)); Vector<Move> moves = findPossibleMoves(board); for(int i=0; i<moves.size(); ++i){ Move move = moves[i]; makeMove(move, board); moveHistory.add(move); if(solvePuzzle(board, marblesLeft-1,exploredBoards, moveHistory)) { return true; } else{ undoMove(move, board); moveHistory.remove(moveHistory.size()-1); } } return false; }
int main() { Vector<char> vector; int N; cout << "N> "; cin >> N; for (int i = 0; i < N; ++i) { cout << "\tItem " << i << "> "; char x; cin >> x; vector.insert(x); } vector.print(); while (true) { cout << "Remove> "; int i; cin >> i; vector.remove(i); vector.print(); } return 0; }
Vector<DiogoArc *> dijkstraFindShortestPath(DiogoNode *start, DiogoNode* finish) { Vector<DiogoArc *> path; SimplePiorityQueue<Vector<DiogoArc *>> queue; Map<string, int> fixed; while (start != finish) { if (!fixed.containsKey(start->getName())) //If hasnt reached this node, meaning is the shortest/first path to this { fixed.add(start->getName(), getPathCost(path)); //Cached the visited node, with the current path cost because its the lowest (first one to arrive) for (DiogoArc *arc: *(start->getArcs())) //Queue up the next nodes to continue the checking, having the cost as the priority so the next path dequeued is the closest one { path.add(arc); queue.enqueue(path, getPathCost(path)); path.remove(path.size() - 1); } } if(queue.isEmpty()) //went through all the arcs and paths and didnt reach the finish node { path.clear(); return path; //return empty path; } path = queue.dequeue(); start = path[path.size() - 1]->getFinish(); //change the start to the last node reached and continue the search for the finish node } return path; }
void TestPopAndRemove() { Vector* vector = VectorInit(DEFAULT_CAPACITY); vector->set_clean(vector, CleanElement); void* dummy; CU_ASSERT(vector->pop_back(vector) == false); unsigned i; for (i = 0 ; i < SIZE_MID_TEST ; ++i) { Tuple* tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = i; tuple->second = i; vector->push_back(vector, tuple); } /* Pop elements ranging from (SML * 3) to MID from the vector tail. */ for (i = 0 ; i < SIZE_SML_TEST ; ++i) CU_ASSERT(vector->pop_back(vector) == true); CU_ASSERT(vector->get(vector, SIZE_SML_TEST * 3, &dummy) == false); CU_ASSERT(vector->get(vector, SIZE_MID_TEST, &dummy) == false); /* Remove elements ranging from (SML * 2) to (SML * 3) from the vector tail. */ for (i = SIZE_SML_TEST * 3 - 1 ; i >= SIZE_SML_TEST << 1 ; --i) CU_ASSERT(vector->remove(vector, i) == true); CU_ASSERT(vector->get(vector, SIZE_SML_TEST << 1, &dummy) == false); CU_ASSERT(vector->remove(vector, SIZE_SML_TEST << 1) == false); CU_ASSERT(vector->remove(vector, SIZE_MID_TEST) == false); /* Remove elements ranging from 0 to SML from the vector head. */ for (i = 0 ; i < SIZE_SML_TEST ; ++i) CU_ASSERT(vector->remove(vector, 0) == true); CU_ASSERT(vector->get(vector, SIZE_SML_TEST, &dummy) == false); unsigned num = SIZE_SML_TEST; for (i = 0 ; i < SIZE_SML_TEST ; ++i) { void* tuple; CU_ASSERT(vector->get(vector, i, &tuple) == true); CU_ASSERT_EQUAL(((Tuple*)tuple)->first, num); ++num; } CU_ASSERT_EQUAL(vector->size(vector), SIZE_SML_TEST); CU_ASSERT_EQUAL(vector->capacity(vector), SIZE_MID_TEST); VectorDeinit(vector); }
bool RuleFeatureSet::invalidateStyleForClassChange(Element* element, Vector<AtomicString>& invalidationClasses, bool foundInvalidationSet) { int oldSize = invalidationClasses.size(); if (element->needsStyleInvalidation()) { if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(element)) { foundInvalidationSet = true; for (InvalidationList::const_iterator it = invalidationList->begin(); it != invalidationList->end(); ++it) { if ((*it)->wholeSubtreeInvalid()) { element->setNeedsStyleRecalc(SubtreeStyleChange); invalidationClasses.remove(oldSize, invalidationClasses.size() - oldSize); element->clearChildNeedsStyleInvalidation(); return true; } (*it)->getClasses(invalidationClasses); } } } bool thisElementNeedsStyleRecalc = false; if (element->hasClass()) { const SpaceSplitString& classNames = element->classNames(); for (Vector<AtomicString>::const_iterator it = invalidationClasses.begin(); it != invalidationClasses.end(); ++it) { if (classNames.contains(*it)) { thisElementNeedsStyleRecalc = true; break; } } } // foundInvalidationSet will be true if we are in a subtree of a node with a DescendantInvalidationSet on it. // We need to check all nodes in the subtree of such a node. if (foundInvalidationSet || element->childNeedsStyleInvalidation()) { bool someChildrenNeedStyleRecalc = invalidateStyleForClassChangeOnChildren(element, invalidationClasses, foundInvalidationSet); // We only need to possibly recalc style if this node is in the subtree of a node with a DescendantInvalidationSet on it. if (foundInvalidationSet) thisElementNeedsStyleRecalc = thisElementNeedsStyleRecalc || someChildrenNeedStyleRecalc; } if (thisElementNeedsStyleRecalc) element->setNeedsStyleRecalc(LocalStyleChange); invalidationClasses.remove(oldSize, invalidationClasses.size() - oldSize); element->clearChildNeedsStyleInvalidation(); return thisElementNeedsStyleRecalc; }
/* * Function: genWords * -------------------- * Creates the N-gram map * * Preconditions: * * @param: nMap = the map that we are basing our words off of * N = the number of words, n, to use in N-gram * @return: returns nothing */ void genWords(Map<Vector<string>, Vector<string>> &nMap, int N) { // Initialize proceed flag to false bool proceedFlag = false; int nWords = 0; // Ask the user for input on number of words and do some sanity checks while(!proceedFlag){ cout << endl; string numWords = getLine("# of random words to generate (0 to quit)?"); if(stringIsInteger(numWords)) { nWords = stringToInteger(numWords); if(nWords==0) return; if(stringToInteger(numWords)>=N) { proceedFlag=true; } else{ cout <<"N must be " +integerToString(N)+ " or greater"<<endl; } } else{ cout<< "Illegal integer format. Try again."<<endl; } } int mapSize = nMap.size(); // Get size of map srand(time(NULL)); // Seed the random number generator with the time int random = rand()%mapSize; // Get random number from 0 to size of map Vector<Vector<string>> keys = nMap.keys(); Vector<string> startVector = keys[random]; // Print ellipses for formatting cout << "... "; for(int i=0;i<startVector.size();i++){ cout << startVector[i] + " "; } // Count the words that we already printed int count = 0; count += N-1; while(count<nWords){ // Find the keys corresponding to start vector Vector<string> values = nMap.get(startVector); // Randomly choose one of the keys int valSize = values.size(); // Get size of map random = rand()%valSize; // Get random number from 0 to size of values // print the key with correct formatting cout << values[random] + " "; // drop the first index of the startVector startVector.remove(0); // Add the randomly chosen key to the start vector startVector.add(values[random]); // repeat process count++; } // Extra line and ellipses for formatting cout << "..." << endl; // Rerun program until user quits genWords(nMap,N); }
void putMap(Map<Vector<string>, Vector<string> >& nGramMap, Vector<string> & inputVect, const string &inputWord) { if(!nGramMap.containsKey(inputVect)) { nGramMap.add(inputVect, Vector<string>()); } nGramMap[inputVect].add(inputWord); inputVect.remove(0); inputVect.add(inputWord); }
template<class T, size_t n> static void removeFromVector(Vector<T*, n> & vec, T* item) { size_t size = vec.size(); for (size_t i = 0; i != size; ++i) if (vec[i] == item) { vec.remove(i); break; } }
EncodedJSValue JSC_HOST_CALL Interpreter::callNativeErrorConstructor(ExecState* exec) { JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); Vector<StackFrame> stackTrace; exec->vm().interpreter->getStackTrace(stackTrace, std::numeric_limits<size_t>::max()); stackTrace.remove(0); return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace)); }
void FEMorphology::platformApplyGeneric(PaintingData* paintingData, int yStart, int yEnd) { Uint8ClampedArray* srcPixelArray = paintingData->srcPixelArray; Uint8ClampedArray* dstPixelArray = paintingData->dstPixelArray; const int width = paintingData->width; const int height = paintingData->height; const int effectWidth = width * 4; const int radiusX = paintingData->radiusX; const int radiusY = paintingData->radiusY; Vector<unsigned char> extrema; for (int y = yStart; y < yEnd; ++y) { int extremaStartY = std::max(0, y - radiusY); int extremaEndY = std::min(height - 1, y + radiusY); for (unsigned int clrChannel = 0; clrChannel < 4; ++clrChannel) { extrema.clear(); // Compute extremas for each columns for (int x = 0; x <= radiusX; ++x) { unsigned char columnExtrema = srcPixelArray->item(extremaStartY * effectWidth + 4 * x + clrChannel); for (int eY = extremaStartY + 1; eY < extremaEndY; ++eY) { unsigned char pixel = srcPixelArray->item(eY * effectWidth + 4 * x + clrChannel); if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema) || (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema)) { columnExtrema = pixel; } } extrema.append(columnExtrema); } // Kernel is filled, get extrema of next column for (int x = 0; x < width; ++x) { const int endX = std::min(x + radiusX, width - 1); unsigned char columnExtrema = srcPixelArray->item(extremaStartY * effectWidth + endX * 4 + clrChannel); for (int i = extremaStartY + 1; i <= extremaEndY; ++i) { unsigned char pixel = srcPixelArray->item(i * effectWidth + endX * 4 + clrChannel); if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema) || (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema)) columnExtrema = pixel; } if (x - radiusX >= 0) extrema.remove(0); if (x + radiusX <= width) extrema.append(columnExtrema); unsigned char entireExtrema = extrema[0]; for (unsigned kernelIndex = 1; kernelIndex < extrema.size(); ++kernelIndex) { if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && extrema[kernelIndex] <= entireExtrema) || (m_type == FEMORPHOLOGY_OPERATOR_DILATE && extrema[kernelIndex] >= entireExtrema)) entireExtrema = extrema[kernelIndex]; } dstPixelArray->set(y * effectWidth + 4 * x + clrChannel, entireExtrema); } } } }
void HTMLPropertiesCollection::findPropetiesOfAnItem(Node* root) const { // 5.2.5 Associating names with items. Vector<Node*> memory; memory.append(root); Vector<Node*> pending; // Add the child elements of root, if any, to pending. for (Node* child = root->firstChild(); child; child = child->nextSibling()) if (child->isHTMLElement()) pending.append(child); // If root has an itemref attribute, split the value of that itemref attribute on spaces. // For each resulting token ID, if there is an element in the home subtree of root with the ID ID, // then add the first such element to pending. if (toHTMLElement(root)->fastHasAttribute(itemrefAttr)) { DOMSettableTokenList* itemRef = root->itemRef(); for (size_t i = 0; i < itemRef->length(); ++i) { AtomicString id = itemRef->item(i); Element* element = root->document()->getElementById(id); if (element && element->isHTMLElement()) pending.append(element); } } // Loop till we have processed all pending elements while (!pending.isEmpty()) { // Remove first element from pending and let current be that element. Node* current = pending[0]; pending.remove(0); // If current is already in memory, there is a microdata error; if (memory.contains(current)) { // microdata error; continue; } memory.append(current); // If current does not have an itemscope attribute, then: add all the child elements of current to pending. HTMLElement* element = toHTMLElement(current); if (!element->fastHasAttribute(itemscopeAttr)) { for (Node* child = current->firstChild(); child; child = child->nextSibling()) if (child->isHTMLElement()) pending.append(child); } // If current has an itemprop attribute specified, add it to results. if (element->fastHasAttribute(itempropAttr)) m_properties.append(current); } }