コード例 #1
0
ファイル: ast.c プロジェクト: wjlandryiii/mycc
void printAST(struct ast_node *node){
	int i;
	struct set_iterator si;
	int value;

	if(node->leafNumber >= 0){
		printf("%d: nullable:[%s] ", node->leafNumber, node->nullable ? "YES" : "NO");
		printf("firstpos:[ ");
		si = setIterator(node->firstpos);
		while(nextSetItem(&si, &value)){
			printf("%d ", value);
		}
		printf("] lastpos:[ ");
		si = setIterator(node->lastpos);
		while(nextSetItem(&si, &value)){
			printf("%d ", value);
		}
		printf("] followpos:[ ");
		si = setIterator(node->followpos);
		while(nextSetItem(&si, &value)){
			printf("%d ", value);
		}
		printf("]\n");
	}
	if(node->child0){
		printAST(node->child0);
	}
	if(node->child1){
		printAST(node->child1);
	}
}
コード例 #2
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
void shiftBackward(TreeIteratorPtr it, unsigned int shift){
    TreeNodePtr node = it->node;
    int pos = it->pos;
    bool found = false;

    while(!found){
        if(isLeaf(node)){
            if(shift <= pos){
                pos -= shift;
                shift = 0;
                found = true;
            } else{
                shift -= pos;
                pos = 0;
            }
        } else{
            for(pos; pos >= 0 && !found; pos--){
                if(shift <= node->subtreeKeyCount[pos]){
                    found = true;
                    node = node->nodes[pos];
                    pos = node->keyCount;
                }
                if(found) break;//for

                shift -= node->subtreeKeyCount[pos];
                shift--;
                if(!shift) found = pos >= 0;
            }
            
            if(shift && found){
                found = false;
                continue;
            }
        }
        if(!found){
            if(isRoot(node)){
                setIterator(it, NULL, 0, IT_BEFORE_FIRST);
                return;
            }
            assert(node->parent != NULL && node->parent->nodes != NULL);
            while(node->parent->nodes[0] == node){

                node = node->parent;
                if(isRoot(node)){
                    setIterator(it, NULL, 0, IT_BEFORE_FIRST);
                    return;
                }
                assert(node->parent != NULL && node->parent->nodes != NULL);
            }
            
            //now the node isn't first in parent's children. go lurk there
            pos = getItemOrNext(node->parent, node->items[0]->key) - 1;
            node = node->parent;
            shift--;
            found = !shift;
        }
    }
    setIterator(it, node, pos, IT_NORMAL);
}
コード例 #3
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
void shiftForward(TreeIteratorPtr it, unsigned int shift){
    TreeNodePtr node = it->node;
    int pos = it->pos;
    bool found = false;

    while(!found){
        if(!isLeaf(node)){
            for(pos++; pos < node->childCount && !found; pos++){
                if(shift <= node->subtreeKeyCount[pos]){
                    found = true;
                    node = node->nodes[pos];
                    pos = -1;
                }
                if(found) break;//get outta for

                shift -= node->subtreeKeyCount[pos];
                shift--;//passing key
                
                if(!shift) found = pos < node->keyCount;
                if(found) break;//get outta for

            }
            if(shift && found){
                found = false;
                continue;
            }
        } else{//if isLeaf
            if(pos + shift <= node->keyCount){
                pos += shift;
                shift = 0;
                found = pos < node->keyCount;
            } else{
                shift -= node->keyCount - pos;
                pos = node->keyCount;
                assert(!found);
            }
        }
        if(!found){//climb up
            if(isRoot(node)){
                setIterator(it, NULL, 0, IT_PAST_REAR);
                return;
            }
            assert(node->parent != NULL && node->parent->nodes != NULL);
            while(node->parent->nodes[node->parent->childCount - 1] == node){

                node = node->parent;
                if(isRoot(node)){
                    setIterator(it, NULL, 0, IT_PAST_REAR);
                    return;
                }
                assert(node->parent != NULL && node->parent->nodes != NULL);
            }
            pos = getItemOrNext(node->parent, node->items[0]->key);
            node = node->parent;
            found = !shift;
        }
    }
    setIterator(it, node, pos, IT_NORMAL);
}
コード例 #4
0
ファイル: moonwalker.cpp プロジェクト: oivoodoo/MoonWalker
void MoonWalker::render(VoodooGraphics graphics, int elapsed)
{
    graphics.painter()->save();

    // если нужно создать наклон для машинки

    if(position()->x() >= 0 && position()->x() <= 30)
    {
        setAlpha(1);
    } else if (position()->x() >= 30 && position()->x() <= 50)
    {
        setAlpha(2);
    } else if (position()->x() >= 100 && position()->x() <= 300)
    {
        setAlpha(-1);
    } else if (position()->x() >= 300 && position()->x() <= 510)
    {
        setAlpha(1);
    } else if (position()->x() >= 510 && position()->x() <= 800)
    {
        setAlpha(-4);
    }

    // тело машины
    drawLines(graphics, lines1);
    // кабинка
    drawLines(graphics, lines2);
    // антенна
    drawLines(graphics, lines3);

    QPoint point;
    qint32 radius = 1 * scale();
    for(int i = 0; i < 4; i++)
    {
        point = graphics.rotate(10 * scale() - i * radius * 2, 7 * scale(), alpha());
        graphics.drawCircle(point.x() + position()->x(), point.y() + position()->y(), radius);
        graphics.drawCircle(point.x() + position()->x(), point.y() + position()->y(), elapsed / 160);
    }

    // антенна
    point = graphics.rotate(12 * scale(), 0, alpha());
    graphics.drawCircle(position()->x() + point.x(), position()->y() + point.y(), 1 * scale());
    graphics.drawCircle(position()->x() + point.x(), position()->y() + point.y(), 5);
    graphics.drawCircle(position()->x() + point.x(), position()->y() + point.y(), elapsed / 20);

    if (position()->x() >= width() + 10)
    {
        setPosition(0, position()->y());
        setIterator(0);
    }

    setPosition(iterator() + 1, position()->y());
    setIterator(iterator() + 1);
    graphics.painter()->restore();
}
コード例 #5
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
void LSQ_SetPosition(LSQ_IteratorT iterator, LSQ_IntegerIndexT pos){
    TreeIteratorPtr it = iterator;
    
    if(pos < 0 || pos >= it->tree->size){
        setIterator(it, NULL, 0, pos < 0 ? IT_BEFORE_FIRST : IT_PAST_REAR);
        return;
    }

    TreeNodePtr root = it->tree->root;
    setIterator(it, root, 0, IT_NORMAL);
    LSQ_ShiftPosition(it, pos - (isLeaf(root) ? 0 : root->subtreeKeyCount[0]));
}
コード例 #6
0
ファイル: ast.c プロジェクト: wjlandryiii/mycc
int astFollowposAttribute(struct ast *ast, struct ast_node *node){
	if(node->op == OP_OR){
		astFollowposAttribute(ast, node->child0);
		astFollowposAttribute(ast, node->child1);

		node->followpos = newSet();
		return 0;
	} else if(node->op == OP_CAT){
		astFollowposAttribute(ast, node->child0);
		astFollowposAttribute(ast, node->child1);

		node->followpos = newSet();
		struct set_iterator si;
		int leafNumber;
		si = setIterator(node->child0->lastpos);
		while(nextSetItem(&si, &leafNumber)){
			struct ast_node *leafNode;
			assert(leafNumber < leafCount);
			leafNode = leafIndex[leafNumber];
			setAddSet(leafNode->followpos, node->child1->firstpos);
		}
		return 0;
	} else if(node->op == OP_STAR){
		astFollowposAttribute(ast, node->child0);

		node->followpos = newSet();
		struct set_iterator si;
		int leafNumber;

		si = setIterator(node->lastpos);
		while(nextSetItem(&si, &leafNumber)){
			struct ast_node *leafNode;
			assert(leafNumber < leafCount);
			leafNode = leafIndex[leafNumber];
			setAddSet(leafNode->followpos, node->firstpos);
		}
		return 0;
	} else if(node->op == OP_LITERAL){
		node->followpos = newSet();
		return 0;
	} else if(node->op == OP_EPSILON){
		node->followpos = newSet();
		return 0;
	} else {
		fprintf(stderr, "unknown op: %d\n", node->op);
		exit(1);
	}
}
コード例 #7
0
bool CardDatabase::saveToFile(const QString &fileName, bool tokens)
{
    QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly))
        return false;
    QXmlStreamWriter xml(&file);

    xml.setAutoFormatting(true);
    xml.writeStartDocument();
    xml.writeStartElement("cockatrice_carddatabase");
    xml.writeAttribute("version", QString::number(versionNeeded));

    if (!tokens) {
        xml.writeStartElement("sets");
        QHashIterator<QString, CardSet *> setIterator(sets);
        while (setIterator.hasNext())
            xml << setIterator.next().value();
        xml.writeEndElement(); // sets
    }

    xml.writeStartElement("cards");
    QHashIterator<QString, CardInfo *> cardIterator(cards);
    while (cardIterator.hasNext()) {
        CardInfo *card = cardIterator.next().value();
        if (tokens == card->getIsToken()) {
            xml << card;
        }
    }
    xml.writeEndElement(); // cards

    xml.writeEndElement(); // cockatrice_carddatabase
    xml.writeEndDocument();

    return true;
}
コード例 #8
0
ファイル: JSMapIterator.cpp プロジェクト: ollie314/webkit
JSMapIterator* JSMapIterator::clone(ExecState* exec)
{
    VM& vm = exec->vm();
    auto clone = JSMapIterator::create(vm, exec->callee()->globalObject()->mapIteratorStructure(), m_map.get(), m_kind);
    clone->setIterator(vm, m_iter.get());
    return clone;
}
コード例 #9
0
 IAggregate<std::string>::Iterator IteratorTest::getIterator(void) const
 {
     IAggregate<std::string>::Iterator result(new IteratorTest::Iterator());
     setIterator(*result);
     return result;
 }
コード例 #10
0
 void IteratorTest::setIterator(IIterator<std::string>& iterator) const
 {
     IteratorTest::Iterator* result;
     result = dynamic_cast<IteratorTest::Iterator*>(&iterator);
     setIterator(*result);
 }
コード例 #11
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
TreeIteratorPtr newTreeIterator(TreePtr tree, TreeNodePtr node, int pos, TreeIteratorState state){
    TreeIteratorPtr it = malloc(sizeof(TreeIterator));
    it->tree = tree;
    setIterator(it, node, pos, state);
    return it;
}
コード例 #12
0
ファイル: cachingreader.cpp プロジェクト: nicholasjohns/mixxx
void CachingReader::hintAndMaybeWake(const QVector<Hint>& hintList) {
    // If no file is loaded, skip.
    if (m_readerStatus != TRACK_LOADED) {
        return;
    }

    QVectorIterator<Hint> iterator(hintList);

    // To prevent every bit of code having to guess how many samples
    // forward it makes sense to keep in memory, the hinter can provide
    // either 0 for a forward hint or -1 for a backward hint. We should
    // be calculating an appropriate number of samples to go backward as
    // some function of the latency, but for now just leave this as a
    // constant. 2048 is a pretty good number of samples because 25ms
    // latency corresponds to 1102.5 mono samples and we need double
    // that for stereo samples.
    const int default_samples = 2048;

    QSet<int> chunksToFreshen;
    while (iterator.hasNext()) {
        // Copy, don't use reference.
        Hint hint = iterator.next();

        if (hint.length == 0) {
            hint.length = default_samples;
        } else if (hint.length == -1) {
            hint.sample -= default_samples;
            hint.length = default_samples;
            if (hint.sample < 0) {
                hint.length += hint.sample;
                hint.sample = 0;
            }
        }
        if (hint.length < 0) {
            qDebug() << "ERROR: Negative hint length. Ignoring.";
            continue;
        }
        int start_sample = math_max(0, math_min(
                                        m_iTrackNumSamplesCallbackSafe, hint.sample));
        int start_chunk = chunkForSample(start_sample);
        int end_sample = math_max(0, math_min(
                                      m_iTrackNumSamplesCallbackSafe, hint.sample + hint.length - 1));
        int end_chunk = chunkForSample(end_sample);

        for (int current = start_chunk; current <= end_chunk; ++current) {
            chunksToFreshen.insert(current);
        }
    }

    // For every chunk that the hints indicated, check if it is in the cache. If
    // any are not, then wake.
    bool shouldWake = false;
    QSetIterator<int> setIterator(chunksToFreshen);
    while (setIterator.hasNext()) {
        int chunk = setIterator.next();

        // This will cause the chunk to be 'freshened' in the cache. The
        // chunk will be moved to the end of the LRU list.
        if (!m_chunksBeingRead.contains(chunk) && lookupChunk(chunk) == NULL) {
            shouldWake = true;
            Chunk* pChunk = allocateChunkExpireLRU();
            if (pChunk == NULL) {
                qDebug() << "ERROR: Couldn't allocate spare Chunk to make ChunkReadRequest.";
                continue;
            }
            m_chunksBeingRead.insert(chunk, pChunk);
            ChunkReadRequest request;
            pChunk->chunk_number = chunk;
            request.chunk = pChunk;
            // qDebug() << "Requesting read of chunk" << chunk << "into" << pChunk;
            // qDebug() << "Requesting read into " << request.chunk->data;
            if (m_chunkReadRequestFIFO.write(&request, 1) != 1) {
                qDebug() << "ERROR: Could not submit read request for "
                         << chunk;
            }
            //qDebug() << "Checking chunk " << chunk << " shouldWake:" << shouldWake << " chunksToRead" << m_chunksToRead.size();
        }
    }

    // If there are chunks to be read, wake up.
    if (shouldWake) {
        m_pWorker->workReady();
    }
}
コード例 #13
0
ファイル: ast.c プロジェクト: wjlandryiii/mycc
int graphEmitNode(struct ast_node *node){
	int i;

	printf("\tnode%d ", graphNodeNumber);
	printf("[ ");
	{
		printf("style = filled");
		printf(", shape = rectangle");
		printf(", label = \"");
		if(node->op == OP_OR){
			printf("\\|\\n");
		} else if(node->op == OP_CAT){
			printf("o\\n");
		} else if(node->op == OP_STAR){
			printf("*\\n");
		} else if(node->op == OP_LITERAL){
			if(isalnum(node->c)){
				printf("%c:%d\n", node->c, node->leafNumber);
			} else if(isgraph(node->c)){
				printf("\\%c:%d\\n", node->c, node->leafNumber);
			} else {
				printf("0x%02x:%d\\n", node->c, node->leafNumber);
			}
		} else if(node->op == OP_EPSILON){
			printf("\\{\\}\\n");
		} else {
			fprintf(stderr, "graphEmitNode() invalid op: %d\n", node->op);
			exit(1);
		}

		struct set_iterator si;
		int value;
		printf("nullable: %s\\n", node->nullable ? "YES" : "NO");
		printf("firstpos: ");
		{
			printf("[ ");
			si = setIterator(node->firstpos);
			while(nextSetItem(&si, &value)){
				printf("%d ", value);
			}
			printf("]\\n");
		}
		printf("lastpos: ");
		{
			printf("[ ");
			si = setIterator(node->lastpos);
			while(nextSetItem(&si, &value)){
				printf("%d ", value);
			}
			printf("]\\n");
		}
		printf("followpos: ");
		{
			printf("[ ");
			si = setIterator(node->followpos);
			while(nextSetItem(&si, &value)){
				printf("%d ", value);
			}
			printf("]\\n");
		}

		printf("\"");

		if(node->leafNumber >= 0){
			printf(", fillcolor = green");
		} else {
			printf(", fillcolor = white");
		}
	}
	printf("]\n");

	return graphNodeNumber++;
}
コード例 #14
0
ファイル: JSMapIterator.cpp プロジェクト: ollie314/webkit
void JSMapIterator::finishCreation(VM& vm, JSMap* iteratedObject)
{
    Base::finishCreation(vm);
    m_map.set(vm, this, iteratedObject);
    setIterator(vm, m_map->impl()->head());
}