Ejemplo n.º 1
0
void ProtectedNode::sortAllProtectedChildren()
{
    if( _reorderProtectedChildDirty ) {
        sortNodes(_protectedChildren);
        _reorderProtectedChildDirty = false;
    }
}
Ejemplo n.º 2
0
 void DspChain::sortNodes(set<sDspNode>& nodes, ulong& index, sDspNode node) throw(DspError&)
 {
     if(!node->index)
     {
         nodes.insert(node);
         for(vector<sDspNode>::size_type i = 0; i < node->getNumberOfInputs(); i++)
         {
             DspNodeSet& link = node->m_inputs[i]->m_links;
             for(auto it = link.begin(); it != link.end(); ++it)
             {
                 sDspNode input = (*it).lock();
                 if(input && !input->index)
                 {
                     if(nodes.find(input) != nodes.end())
                     {
                         throw DspError(input, DspError::Loop);
                     }
                     else
                     {
                         sortNodes(nodes, index, input);
                     }
                 }
             }
         }
         
         nodes.erase(node);
         node->index = index++;
     }
 }
Ejemplo n.º 3
0
void ZoneGraph::updateGraph()
    {
    if(mDiagramChanged & ZDC_Nodes)
        {
        clearGraph();
        for(auto const &type : mModel->mTypes)
            {
            ModelClassifier const *cls = ModelClassifier::getClass(type.get());
            if(cls && cls->getModule() != nullptr)
                {
                if(!isFiltered(cls->getModule(), mFilteredModules))
                    {
                    mNodes.push_back(ZoneNode(type.get()));
                    }
                }
            }
        mDrawOptions.initDrawOptions(mNodes.size() < 500);
        sortNodes();
        }
    if(mDiagramChanged & ZDC_Connections)
        {
        updateConnections();
        }
    mDiagramChanged = ZDC_None;
    }
Ejemplo n.º 4
0
void Exporter::sortNodes(NiNodeRef node)
{
   node->SortChildren(SortNodeEquivalence());

   vector<NiNodeRef> children = DynamicCast<NiNode>(node->GetChildren());
   for (vector<NiNodeRef>::iterator itr = children.begin(); itr != children.end(); ++itr)
      sortNodes(*itr);
}
Ejemplo n.º 5
0
    void Layer::sortNodes(int first, int size)
    {
        Node *pivot;
        int last = first + size - 1;
        int middle;
        int lower = first;
        int higher = last;

        if (size <= 1)
            return;

        middle = findMiddleNode(first, size);
        pivot = mNodes[middle];
        mNodes[middle] = mNodes[first];

        while (lower < higher)
        {
            while ((pivot->getPosition().y - pivot->getHeight()) <
                   (mNodes[higher]->getPosition().y - mNodes[higher]->getHeight()) &&
                   lower < higher)
                --higher;

            if (higher != lower)
            {
                mNodes[lower] = mNodes[higher];
                ++lower;
            }

            while ((pivot->getPosition().y - pivot->getHeight()) >
                   (mNodes[lower]->getPosition().y - mNodes[lower]->getHeight()) &&
                   lower < higher)
                ++lower;

            if (higher != lower)
            {
                mNodes[higher] = mNodes[lower];
                --higher;
            }
        }

        mNodes[lower] = pivot;
        sortNodes(first, lower - first);
        sortNodes(lower + 1, last - lower);
    }
void Timeline::addNode(){
    
    AnimationNode thisNode;
    thisNode.setup(nodes[selectedNode]);
    thisNode.time = curTime;
    if (lockToGrid){
        int numTime = (curTime+gridTimeStep*0.5) / gridTimeStep;
        thisNode.time = numTime * gridTimeStep;
        thisNode.time = MIN(thisNode.time, maxTime);
    }
    nodes.insert(nodes.begin()+selectedNode+1, thisNode);

    sortNodes();
}
Ejemplo n.º 7
0
 void DspChain::start() throw(DspError&)
 {
     if(m_running)
     {
         stop();
     }
     
     lock_guard<mutex> guard(m_mutex);
     
     for(vector<sDspLink>::size_type i = 0; i < m_links.size(); i++)
     {
         m_links[i]->start();
     }
     for(vector<sDspNode>::size_type i = 0; i < m_nodes.size(); i++)
     {
         m_nodes[i]->index = 0;
     }
     
     ulong index = 1;
     set<sDspNode> temp;
     for(vector<sDspNode>::size_type i = 0; i < m_nodes.size(); i++)
     {
         try
         {
             sortNodes(temp, index, m_nodes[i]);
         }
         catch(DspError& e)
         {
             throw e;
         }
     }
     temp.clear();
     
     for(vector<sDspNode>::size_type i = 0; i < m_nodes.size(); i++)
     {
         try
         {
             m_nodes[i]->start();
         }
         catch(DspError& e)
         {
             throw e;
         }
     }
     
     m_running = true;
 }
Ejemplo n.º 8
0
void makeHuffmanTree( Node** out, long* frequency, int numChars, Node** pListBuf ){
	Node* start = makeNodeList( frequency, numChars );
	
	// Store base pointers in the list for quick access while encoding.
	
	Node* sorted;
    Node* arr;
	//Assume sorted is a new array.


	sortNodes( start, &sorted, &arr );
	
	for (int i = 0; i < numChars; i++ ) {
		pListBuf[i] = arr + i;
	}

	while (1) {
		Node* n1 = sorted;
		Node* n2 = sorted->next;
		if( n2 == NULL )
			break;
		Node* merged = newNode( 0, n1->freq + n2->freq );
		
        printf("Merging %ld, %ld\n", n1->freq, n2->freq);fflush( stdout );
		merged->left = n1;
		merged->right = n2;
		
		n1->parent = merged;
		n2->parent = merged;
		
		sorted = (sorted->next->next);
        if( sorted != NULL )
		    sorted = insertSorted( sorted, merged );
        else
            sorted = merged;
	}
	*out = sorted;
	
}
float Timeline::mouseDragged(int x, int y, int button){
    
    //if the mosue was not inside, just return -1
    if (!mouseStartedInside){
        return -1;
    }
    
    //figure out where we are in the timeline
    float prc = (x-offset.x) / drawW;
    prc = CLAMP(prc, 0, 1);
    float time = maxTime * prc;
    
    //lock to grid if it is on
    if (lockToGrid){
        int numTime = (time+gridTimeStep*0.5) / gridTimeStep;
        time = numTime * gridTimeStep;
        time = MIN(time, maxTime);
    }
    
    //if they just clicked a node, they may ahve just been wanting to set the playhead there, so we wait a bit before dragging or changing the time
    if (nodeBeingDragged){
        
        if (dragFrameTimer < framesToDragNode){
            return nodes[selectedNode].time;
        }
        
        //if we're past that time, we can set the node's time and move on
        //do not do this to the first or last node
        if (selectedNode > 0 && selectedNode < nodes.size()-1){
            nodes[selectedNode].time = time;
            sortNodes();
        }
    }
    
    //if nothing else stoppped us, return the time they dragged the playhead to
    return time;
    
}
Ejemplo n.º 10
0
/* CENTRAL METHOD to parse and render html request*/
int handle(cchar* q0,int conn){
	int len=(int)strlen(q0);
	if(len>1000){
		p("checkSanity len>1000");
		return 0;// SAFETY!
	}
    char* q=editable(q0);
	checkSanity(q,len);
    while(q[0]=='/')q++;
	enum result_format format = html;//txt; html DANGER WITH ROBOTS
	enum result_verbosity verbosity = normal;

	if (eq(q, "favicon.ico"))return 0;
    if(contains(q,"robots.txt")){
        Writeline(conn,"User-agent: *\n");
        Writeline("Disallow: /\n");
        return 0;
    }
	
	char* jsonp=strstr(q,"jsonp");// ?jsonp=fun
	if(jsonp){
		jsonp[-1]=0;
		jsonp+=6;
		format = json;
		}
	else jsonp=(char*)"parseResults";

	if (endsWith(q, ".json")) {
        format = json;
        q[len-5]=0;
    }
    
	if (endsWith(q, ".xml")) {
        format = xml;
        q[len-4]=0;
    }
    
	if (endsWith(q, ".csv")||endsWith(q, ".tsv")) {
        format = csv;
        q[len-4]=0;
    }
    
	if (endsWith(q, ".txt")) {
        format = txt;
        q[len-4]=0;
    }
    
	if (endsWith(q, ".html")) {
		format = html;
		q[len-5]=0;
	}
	if (startsWith(q, ".js")) {
		q[len-3]=0;
		Writeline(conn, jsonp);
		Writeline(conn, "(");
		format = js;
	}
	// todo : dedup!!
	if (startsWith(q, "all/")) {
		cut_to(q," +");
		cut_to(q," -");
		q = q + 4;
		showExcludes=false;
		verbosity = alle;
	}
	if (startsWith(q, "long/")){
		verbosity =  longer;
		q = q + 5;
	}
	if (startsWith(q, "full/")) {
		verbosity =  verbose;
		q = q + 5;
	}
	if (startsWith(q, "verbose/")) {
		verbosity = verbose;
		q = q + 8;
	}
	if (startsWith(q, "short/")) {
		verbosity = shorter;
		q = q + 6;
	}

	if (startsWith(q, "html/")) {
        format = html;
        if(!contains(q,".")&&!contains(q,":"))
			verbosity=verbose;
        q = q + 5;
    }
	if (startsWith(q, "plain/")) {
		format = txt;
		q = q + 6;
	}
	if (startsWith(q, "text/")) {
		format = txt;
		q = q + 5;
	}
	if (startsWith(q, "txt/")) {
		format = txt;
		q = q + 4;
	}
	if (startsWith(q, "xml/")) {
		format = xml;
		q = q + 4;
	}
	if (startsWith(q, "csv/")||startsWith(q, "tsv/")) {
		format = csv;
		q = q + 4;
	}
	if (startsWith(q, "json/")) {
		format = json;
		q = q + 5;
	}
	if (startsWith(q, "js/")) {
		q = q + 3;
		Writeline(conn, jsonp);
		Writeline(conn, "(");
		format = js;
	}
	if (startsWith(q, "long/")) {
		verbosity = longer;
		q = q + 5;
	}
	if (startsWith(q, "verbose/")) {
		verbosity = verbose;
		q = q + 8;
	}
	if (startsWith(q, "short/")) {
		verbosity = shorter;
		q = q + 6;
	}
	if (startsWith(q, "excludes/")||startsWith(q, "includes/")||startsWith(q, "excluded/")||startsWith(q, "included/")||startsWith(q, "showview/")) {
        showExcludes=true;
        verbosity=longer;
		q = q + 9;
	}
    else showExcludes=false;
    excluded.clear();
    included.clear();
    
    if(contains(q,"statement count")){Writeline(conn,itoa((int)context->statementCount).data());return 0;}
    if(contains(q,"node count")){Writeline(conn,itoa(context->nodeCount).data());return 0;}
    
    
	if (startsWith(q, "all/")) {
        cut_to(q," +");
        cut_to(q," -");
		q = q + 4;
		showExcludes=false;
		verbosity = alle;
	}
//	bool get_topic=false;
	bool get_topic=true;
	bool sort=false;
	if (startsWith(q, "ee/")||startsWith(q, "ee ")) {
		q[2]=' ';
		get_topic=true;
	}
	if (startsWith(q, "entities/")) {
		q[8]=' ';
		get_topic=true;
//		verbosity=longer;
	}
	if(hasWord(q)) loadView(q);
    
    if(contains(q,"exclude")||contains(q,"include")){
        verbosity=normal;
        showExcludes=true;
    }
	p(q);
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!
	//
    NodeVector all = parse(q); // <<<<<<<< HANDLE QUERY WITH NETBASE!
    //
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!

	autoIds=false;
    int size=(int)all.size();
    if(showExcludes){
        for (int i = 0; i < size; i++) {
        // todo : own routine!!!
        Node* node = (Node*) all[i];
        if(!contains(all,getAbstract(node->name)))
            all.push_back(getAbstract(node->name));
        N parent= getType(node);
        if(parent){
            if(!contains(all,parent))all.push_back(parent);
            N abs= getAbstract(parent->name);
            if(parent&&!contains(all,abs))all.push_back(abs);
        }
        }
        show(excluded);
    }
    
    const char* html_block="<!DOCTYPE html><html><head><META HTTP-EQUIV='CONTENT-TYPE' CONTENT='text/html; charset=UTF-8'/></head>"\
							"<body><div id='netbase_results'></div>\n<script>var results=";
    //    if((int)all.size()==0)Writeline("0");
	//	Writeline(conn,q);
	char buff[10000];

	bool use_json= format == json || format == js || format == html;
	if (format == xml && (startsWith(q,"select")||contains(q," where "))){Writeline(conn,query2(q));return 0;}
	if (format == xml)Writeline(conn, "<results>\n");
	if (format == html)Writeline(conn,html_block);
	if (use_json)Writeline(conn, "{\"results\":[\n");
	const char* statement_format_xml = "   <statement id='%d' subject=\"%s\" predicate=\"%s\" object=\"%s\" sid='%d' pid='%d' oid='%d'/>\n";
	const char* statement_format_text = "   $%d %s %s %s %d->%d->%d\n";
	const char* statement_format_json = "      { \"id\":%d, \"subject\":\"%s\", \"predicate\":\"%s\", \"object\":\"%s\", \"sid\":%d, \"pid\":%d, \"oid\":%d}";
	const char* statement_format_csv = "%d\t%s\t%s\t%s\t%d\t%d\t%d\n";
	const char* statement_format = 0;
	if (format == xml)statement_format = statement_format_xml;
	if (format == html)statement_format = statement_format_json;
	if (format == json)statement_format = statement_format_json;
	if (format == txt)statement_format = statement_format_text;
	if (format == csv)statement_format = statement_format_csv;
    
	const char* entity_format = 0;
	const char* entity_format_txt = "%s #%d (statements:%d) %s\n";
	const char* entity_format_xml = "<entity name=\"%s\" id='%d' statementCount='%d' description='%s'>\n";
	const char* entity_format_json = "   {\"name\":\"%s\", \"id\":%d, \"statementCount\":%d, \"description\":\"%s\"";
   	const char* entity_format_csv = "%s\t%d\t%d\t%s\n";
    if(all.size()==1)entity_format_csv = "";//statements!
	if (format == xml)entity_format = entity_format_xml;
	if (format == txt)entity_format = entity_format_txt;
	if (format == csv)entity_format = entity_format_csv;
	if (use_json)	  entity_format = entity_format_json;
	Node* last=0;
    warnings=0;
    char* entity=0;
    if(startsWith(q,"all")){
        entity=(char*)cut_to(q," ");
        entity=keep_to(entity,"limit");
    }
   	sortNodes(all);
	int count=(int)all.size();
	int good=0;
	for (int i = 0; i < count && i<resultLimit; i++) {
		Node* node = (Node*) all[i];
		if(!checkNode(node))continue;
		if(node->id==0)continue;
		if(last==node)continue;
		if(eq(node->name,"◊"))continue;
		last=node;
        if(verbosity ==normal && entity&& eq(entity,node->name))continue;
		char* text=getText(node);
//		if(use_json && get_topic){
//			if(empty(text))continue;//! no description = no entity? BAD for amazon etc
//			if(isAbstract(node))continue;
//			N t=getTopic(node);
//		}
		good++;
		if (use_json)if(good>1)Writeline(conn, "},\n");
		sprintf(buff, entity_format, node->name, node->id,node->statementCount,text);
		Writeline(conn, buff);
//        if(verbosity != alle && !get_topic)
//			loadView(node);
		bool got_topic=false;
		if(use_json && get_topic){
			N c=getClass(node);
			N t=getTopic(node);
			N ty=getType(node);
//			if(!c)c=t;
			if(!t)t=ty;
			if(t==node)t=ty;
			if(t!=Entity && checkNode(t)){
				got_topic=true;
				Writeline(conn, ",\n\t \"topicid\":"+itoa(t->id));
				Writeline(conn, ", \"topic\":\""+string(t->name)+"\"");
			}
			if(c && c!=t){
				Writeline(conn, ",\n\t \"classid\":"+itoa(c->id));
				Writeline(conn, ", \"class\":\""+string(c->name)+"\"");
			}
			if(ty&& c!=ty && ty!=t){
				Writeline(conn, ",\n\t \"typeid\":"+itoa(ty->id));
				Writeline(conn, ", \"type\":\""+string(ty->name)+"\"");
			}
		}
		if(use_json)// && (verbosity==verbose||verbosity==shorter))// lol // just name
			Writeline(conn, ", \"kind\":"+itoa(node->kind));
		if((use_json)&&!showExcludes&&node->statementCount>1 && getImage(node)!="")
			Writeline(", \"image\":\""+replace_all(replace_all(getImage(node,150,/*thumb*/true),"'","%27"),"\"","%22")+"\"");
//		if((use_json)&&getText(node)[0]!=0)
//			Writeline(", \"description\":\""+string(getText(node))+"\"");
		Statement* s = 0;
		if (format==csv|| verbosity == verbose || verbosity == longer|| verbosity == alle || showExcludes || ( all.size() == 1 && !(verbosity == shorter))) {
			int count=0;
            //            Writeline(",image:\""+getImage(node->name)+"\"");
			if (use_json)Writeline(conn, ",\n\t \"statements\":[\n");

//			sortStatements(
			deque<Statement*> statements;// sort
			while ((s = nextStatement(node, s))&&count++<lookupLimit){// resultLimit
				if (!checkStatement(s))break;
//				if(!got_topic &&( s->predicate==_Type|| s->predicate==_SuperClass)){
//					addStatementToNode(node, s->id(), true);// next time
//				}
				if(get_topic &&!got_topic && verbosity != verbose && (s->predicate>100 || s->predicate<-100))
					continue;// only important stuff here!
				// filter statements

				if(s->object==0)continue;
//				if(eq(s->Predicate()->name,"Offizielle Website") && !contains(s->Object()->name,"www"))
//					continue;
				if (s->subject==node->id and s->predicate!=4)//_instance
					statements.push_front(s);
				else statements.push_back(s);
			}
//			if(get_topic && verbosity!=shorter){
//				NV topics=getTopics(node);
//				N s=topics[0];
//				for (int j = 0; j < topics.size() && j<=resultLimit; j++) {
//					N s=topics[j];
//					Temporary statement (node,topic,s)
//					statements.push_front(s);
//				}
//			}




			int good=0;
			for (int j = 0; j < statements.size() && j<=resultLimit; j++) {
				s=statements.at(j);
//			while ((s = nextStatement(node, s))&&count++<resultLimit) {
                if(format==csv&&all.size()>1)break;// entities vs statements
                p(s);
				if(verbosity!=alle&&checkHideStatement(s)){warnings++;continue;}
				fixLabels(s);
				if(!(verbosity==verbose||verbosity==alle) && (s->Predicate()==Instance||s->Predicate()==Type))continue;
				if(use_json && good>0)Writeline(conn, ",\n");
				char* objectName=s->Object()->name;

				if(s->Predicate()==Instance){
					N type=findProperty(s->Object(),Type->name,0,50);
					if(  checkNode(type))
						objectName=(char*)(concat(concat(objectName, ": "),type->name));
				}
				sprintf(buff, statement_format, s->id(), s->Subject()->name, s->Predicate()->name, objectName, s->Subject()->id, s->Predicate()->id, s->Object()->id);
				Writeline(conn, buff);
				good++;
			}
			if (use_json)Writeline(conn, "]");
		}
		if (format == xml)Writeline(conn, "</entity>\n");
		//		string img=getImage(node->name);
		//		if(img!="")Writeline(conn,"<img src=\""+img+"\"/>");
	}

	if (use_json || format == html || format == js)Writeline(conn,good>0?"}\n]}":"]}");
	if (format == xml)Writeline(conn, "</results>\n");
	if(format == js)Writeline(conn, ")");// jsonp
		const char* html_end=";\n</script>\n<script src='http://pannous.net/netbase.js'></script></body></html>\n";
	if(format == html)Writeline(conn, html_end);
	//		sprintf(buff,	"<script src='/js/%s'></script>",q0);
	//		Writeline(conn, buff);
	//	}
    pf("Warnings/excluded: %d\n",warnings);
    return 0;// 0K
}