示例#1
0
static inline void disable_bridge_irq(struct irq_data *d)
{
	cpuid_t cpu;
	int swlevel;

	swlevel = find_level(&cpu, d->irq);	/* Criminal offence */
	intr_disconnect_level(cpu, swlevel);
}
示例#2
0
column<typename autocorr_result<T>::var_type> autocorr_result<T>::tau() const
{
    size_t lvl = find_level(DEFAULT_MIN_SAMPLES);
    const column<var_type> &var0 = level_[0].var();
    const column<var_type> &varn = level_[lvl].var();
    const double n = level_[lvl].batch_size();

    return (0.5 * n * varn.array() / var0.array() - 0.5).matrix();
}
示例#3
0
column<typename autocorr_result<T>::var_type> autocorr_result<T>::var() const
{
    size_t lvl = find_level(DEFAULT_MIN_SAMPLES);

    // The question is whether to return the ensemble variance or the batch
    // variance here.  We opt for the batch variance, because it makes
    // everything consistent with each other.
    //return level_[lvl].batch_size() * level_[lvl].var();
    return level_[lvl].var();
}
示例#4
0
文件: set.c 项目: senquack/neverball
static void set_load_hs_v2(fs_file fp, struct set *s, char *buf, int size)
{
    struct score time_score;
    struct score coin_score;

    int set_score = 0;
    int set_match = 1;

    while (fs_gets(buf, size, fp))
    {
        int version = 0;
        int flags = 0;
        int n = 0;

        strip_newline(buf);

        if (strncmp(buf, "set ", 4) == 0)
        {
            get_score(fp, &time_score);
            get_score(fp, &coin_score);

            set_score = 1;
        }
        else if (sscanf(buf, "level %d %d %n", &flags, &version, &n) >= 2)
        {
            struct level *l;

            if ((l = find_level(s, buf + n)))
            {
                /* Always prefer "locked" flag from the score file. */

                l->is_locked = !!(flags & LEVEL_LOCKED);

                /* Only use "completed" flag and scores on version match. */

                if (version == l->version_num)
                {
                    l->is_completed = !!(flags & LEVEL_COMPLETED);

                    get_score(fp, &l->scores[SCORE_TIME]);
                    get_score(fp, &l->scores[SCORE_GOAL]);
                    get_score(fp, &l->scores[SCORE_COIN]);
                }
                else set_match = 0;
            }
            else set_match = 0;
        }
    }

    if (set_match && set_score)
    {
        s->time_score = time_score;
        s->coin_score = coin_score;
    }
}
示例#5
0
/* Startup one of the (PCI ...) IRQs routes over a bridge.  */
static unsigned int startup_bridge_irq(struct irq_data *d)
{
	struct bridge_controller *bc;
	bridgereg_t device;
	bridge_t *bridge;
	int pin, swlevel;
	cpuid_t cpu;

	pin = SLOT_FROM_PCI_IRQ(d->irq);
	bc = IRQ_TO_BRIDGE(d->irq);
	bridge = bc->base;

	pr_debug("bridge_startup(): irq= 0x%x  pin=%d\n", d->irq, pin);
	/*
	 * "map" irq to a swlevel greater than 6 since the first 6 bits
	 * of INT_PEND0 are taken
	 */
	swlevel = find_level(&cpu, d->irq);
	bridge->b_int_addr[pin].addr = (0x20000 | swlevel | (bc->nasid << 8));
	bridge->b_int_enable |= (1 << pin);
	bridge->b_int_enable |= 0x7ffffe00;	/* more stuff in int_enable */

	/*
	 * Enable sending of an interrupt clear packt to the hub on a high to
	 * low transition of the interrupt pin.
	 *
	 * IRIX sets additional bits in the address which are documented as
	 * reserved in the bridge docs.
	 */
	bridge->b_int_mode |= (1UL << pin);

	/*
	 * We assume the bridge to have a 1:1 mapping between devices
	 * (slots) and intr pins.
	 */
	device = bridge->b_int_device;
	device &= ~(7 << (pin*3));
	device |= (pin << (pin*3));
	bridge->b_int_device = device;

	bridge->b_wid_tflush;

	intr_connect_level(cpu, swlevel);

	return 0;	/* Never anything pending.  */
}
示例#6
0
 inline void
 Depth<SIZE>::change_qty_order(
     Price price,
     int32_t qty_delta,
     bool is_bid
 )
 {
     DepthLevel* level = find_level(price, is_bid, false);
     if (level && qty_delta) {
         if (qty_delta > 0) {
             level->increase_qty(Quantity(qty_delta));
         } else {
             level->decrease_qty(Quantity(std::abs(qty_delta)));
         }
         level->last_change(++last_change_);
     }
     // Ignore if not found - may be beyond our depth size
 }
示例#7
0
std::vector<CompoundSegment*> find_level(bool odd,
				std::vector<std::pair<CompoundSegment*,std::vector<CompoundSegment*> > > &pRet,
				std::vector<CompoundSegment*>& closed_shapes,
				std::vector<std::vector<CompoundSegment*> >& inside_of,
				std::vector<CompoundSegment*> parents)
{
	std::vector<CompoundSegment*> retValue;

	for(unsigned i=0; i < closed_shapes.size(); i++)
	{
		if(inside_of[i].size() != parents.size())
			continue;

		bool no_match = false;
		for(unsigned j=0; j < inside_of[i].size(); j++)
		{
			if(inside_of[i][j] != parents[j])
			{
				no_match = true;
				break;
			}
		}
		if(no_match)
			continue;

		//this closed shape is good to go

		std::vector<CompoundSegment*> nparents = parents;
		nparents.push_back(closed_shapes[i]);
		std::sort(nparents.begin(), nparents.end());

		std::vector<CompoundSegment*> deletions = find_level(!odd,pRet,closed_shapes,inside_of,nparents);

		if(odd)
		{
			pRet.push_back(std::pair<CompoundSegment*,std::vector<CompoundSegment*> >(closed_shapes[i],deletions));
		}
		else
			retValue.push_back(closed_shapes[i]);
	}
	return retValue;
}
示例#8
0
 inline bool
 Depth<SIZE>::close_order(
     Price price,
     Quantity open_qty,
     bool is_bid
 )
 {
     DepthLevel* level = find_level(price, is_bid, false);
     if (level) {
         // If this is the last order on the level
         if (level->close_order(open_qty)) {
             erase_level(level, is_bid);
             return true;
             // Else, mark the level as changed
         } else {
             level->last_change(++last_change_);
         }
     }
     return false;
 }
示例#9
0
 inline void 
 Depth<SIZE>::add_order(
     Price price, 
     Quantity qty, 
     bool is_bid
 ) 
 {
     ChangeId last_change_copy = last_change_;
     DepthLevel* level = find_level(price, is_bid);
     if (level) {
         level->add_order(qty);
         // If this is a visible level
         if (!level->is_excess()) {
             // The depth changed
             last_change_ = last_change_copy + 1; // Ensure incremented
             level->last_change(last_change_copy + 1);
         }
         // The level is not marked as changed if it is not visible
     }
 }
示例#10
0
/* Shutdown one of the (PCI ...) IRQs routes over a bridge.  */
static void shutdown_bridge_irq(struct irq_data *d)
{
	struct bridge_controller *bc = IRQ_TO_BRIDGE(d->irq);
	bridge_t *bridge = bc->base;
	int pin, swlevel;
	cpuid_t cpu;

	pr_debug("bridge_shutdown: irq 0x%x\n", d->irq);
	pin = SLOT_FROM_PCI_IRQ(d->irq);

	/*
	 * map irq to a swlevel greater than 6 since the first 6 bits
	 * of INT_PEND0 are taken
	 */
	swlevel = find_level(&cpu, d->irq);
	intr_disconnect_level(cpu, swlevel);

	bridge->b_int_enable &= ~(1 << pin);
	bridge->b_wid_tflush;
}
示例#11
0
std::vector<TopoDS_Face> MultiPoly(std::list<CSketch*> sketches)
{
	tol = wxGetApp().m_geom_tol;
	shapes.clear();
	//first pass: build lists of closed shapes
	std::list<CSketch*>::iterator it;
	for(it = sketches.begin(); it!= sketches.end(); ++it)
	{
         CSketch* sketch = *it;
		 //Copy this sketches objects into a new list
		 std::list<EndedObject*> sketchobjs;
		 HeeksObj* obj = sketch->GetFirstChild();
		 while(obj)
		 {
			//TODO: for now we only handle EndedObject
		    EndedObject* eobj = dynamic_cast<EndedObject*>(obj);
			if(eobj)
			{
				HArc* arc = dynamic_cast<HArc*>(obj);
				if(arc)
				{
					shapes.push_back(new FastArc(arc->A->m_p,arc->B->m_p,arc->C->m_p,arc->m_axis.Direction().Z() > 0, arc->GetCircle()));
				}
				else
					shapes.push_back(new FastLine(eobj->A->m_p,eobj->B->m_p));
			}
			obj = sketch->GetNextChild();
		 }
	}
	//Get a list of all the intersection points
	Intersector *m_int = new SimpleIntersector();
	std::map<FastCurve*, std::vector<Intersection> > intersections = m_int->Intersect(shapes);

	//Make our flashy double hashmap
	TwoDNearMap bcurves(tol);

	//Create a new list of bounded segment objects. Whose endpoints are locatable via hash
	//with the exception that the hash returns values within tolerance of the specified point
	std::map<FastCurve*, std::vector<Intersection> >::iterator it2;
	for(it2 = intersections.begin(); it2 != intersections.end(); ++it2)
	{
		FastCurve *tline = (*it2).first;
		std::vector<Intersection> inter = (*it2).second;
		for(unsigned i=0; i < inter.size()-1; i++)
		{
			double startu=tline->GetU(inter[i].X,inter[i].Y);
			double newu=tline->GetU(inter[i+1].X,inter[i+1].Y);
			CompoundSegment* segment;
			if(startu < newu)
				segment = new CompoundSegment(tline,tol,startu,newu);
			else
				segment = new CompoundSegment(tline,tol,newu,startu);
			bcurves.insert(inter[i].X,inter[i].Y,segment);
			bcurves.insert(inter[i+1].X,inter[i+1].Y,segment);
			startu = newu;
		}
	}

	//This gets the hashtable working
	bcurves.sort();

	AnalyzeNearMap(bcurves);

	std::vector<CompoundSegment*> closed_shapes;

	//Create a new tree of boundedcurves, that is much smaller. follow all chains and attempt to remove
	//segments that are connected to only 2 other curves. This will yield a non-orientable graph
	//so our definition of polygons better be very graph theoretical
	std::vector<void*> returnvec;

	for(int i=0; i < bcurves.GetVecCount(); i++)
	{
		OneDNearMap* ptMap = bcurves.GetElement(i);
		double x_coord = bcurves.GetCoord(i);
		for(int j=0; j < ptMap->GetVecCount(); j++)
		{
			double y_coord = ptMap->GetCoord(j);
			if(!ptMap->IsValid(j))
				continue;

			returnvec.clear();
			bcurves.find(x_coord,y_coord,returnvec);

			if(returnvec.size() == 1)
			{
				//TODO: this means the current segment is part of an unclosed shape. However it is not clear that
				//this shape is fully concatenated or does not intersect a closed shape. these should probably be removed
				//prior to this loop
				continue;
			}

			if(returnvec.size() != 2)
				continue;

			//Concatenate the 2 groups and remove *it4 from the map
			CompoundSegment* seg1 = (CompoundSegment*)returnvec[0];
			CompoundSegment* seg2 = (CompoundSegment*)returnvec[1];

			if(seg1 == seg2)
			{
				//this means we have found a closed shape. Remove it from the bcurves and add it to a list of closed shapes
				//remove from the map
				bcurves.remove(x_coord,y_coord,seg1);
				bcurves.remove(x_coord,y_coord,seg2);
				closed_shapes.push_back(seg1);
				continue;
			}

			ConcatSegments(x_coord,y_coord,seg1,seg2,bcurves);
		}
	}

	//Now we have a graph of CompoundSegment*. These should be fast to traverse.
	//Non self intersecting shapes are already in closed_shapes
	//We could speed this up by regenerating near_map to get rid of removed references

	bool done=false;
	while(!done)
	{
		bool found=false;
		for(int i=0; i < bcurves.GetVecCount(); i++)
		{
			OneDNearMap* ptMap = bcurves.GetElement(i);
			double x_coord = bcurves.GetCoord(i);
			for(int j=0; j < ptMap->GetVecCount(); j++)
			{
				double y_coord = ptMap->GetCoord(j);
				if(!ptMap->IsValid(j))
					continue;

				returnvec.clear();
				bcurves.find(x_coord,y_coord,returnvec);

				//for most cases, returnvec should have 4 elements. more complicated cases have an even number > 4
				//check for elements that are the same, which mean this polygon could terminate here, so terminate it
				//and merge the other CompoundSegments if there are only two remaining
				int nfound=0;
				for(size_t k=0; k < returnvec.size(); k++)
				{
					for(size_t l=k+1; l < returnvec.size(); l++)
					{
						if(returnvec[k] == returnvec[l])
						{
							//this means we have found a closed shape. Remove it from the bcurves and add it to a list of closed shapes
							//remove from the map
							bcurves.remove(x_coord,y_coord,returnvec[k]);
							bcurves.remove(x_coord,y_coord,returnvec[l]);
							closed_shapes.push_back((CompoundSegment*)returnvec[k]);
							nfound+=2;
							found=true;
						}
					}
				}

				//now we know that no 2 elements in returnvec are equal.
				//make sure there are the right number of elements for our next op
				if(returnvec.size() - nfound != 2)
					continue;

				//Quick and dirty way to get the pointers
				returnvec.clear();
				bcurves.find(x_coord,y_coord,returnvec);

				//Merge the segments and get them out of this coordinate
				ConcatSegments(x_coord,y_coord,(CompoundSegment*)returnvec[0],(CompoundSegment*)returnvec[1],bcurves);
				found=true;
			}
		}
		if(!found)
			done = true;
	}

	//Now that we have all closed shapes, we need to define the relationships. Since we know that they are not intersecting
	//3 kinds of things can happen. A shape is either inside, enclosing, adjacent, or unrelated to another.

	std::vector<std::vector<CompoundSegment*> > inside_of;
	inside_of.resize(closed_shapes.size());

	for(unsigned i=0; i < closed_shapes.size(); i++)
	{
		for(unsigned j=0; j < closed_shapes.size(); j++)
		{
			//We can determine if a shape is inside or outside by finding the winding number of just 1 point with the
			//entire other polygon

			if(i==j)
				continue;

			int rays = closed_shapes[i]->GetRayIntersectionCount(closed_shapes[j]->Begin());
			if(rays%2)
			{
				//Polygon J is inside of polygon I
				inside_of[j].push_back(closed_shapes[i]);
				int x=0;
				x++;
			}
		}
	}

	//This is used to reverse the ordering of a closed shape. Getting it to be CW or CCW
	//OCC is picky about the ordering when the polygon has holes

	for(unsigned i=0; i < closed_shapes.size(); i++)
	{
		closed_shapes[i]->Order();
#ifdef FORCEPOLYGONORDERING
		bool cw = closed_shapes[i]->GetCW();
		if(!cw)
		{
			closed_shapes[i]->Reverse();
			closed_shapes[i]->Order();
		}
#endif
	}


	//Sort these lists for easy comparison
	for(unsigned i=0; i < inside_of.size(); i++)
	{
		std::sort(inside_of[i].begin(),inside_of[i].end());
	}

	//Now we want to descend into this thing. First find all shapes that are inside of nothing else
	std::vector<std::pair<CompoundSegment*,std::vector<CompoundSegment*> > > gold;
	find_level(true,gold,closed_shapes,inside_of,std::vector<CompoundSegment*>());

	return TopoDSFaceAdaptor(gold);
}
示例#12
0
double autocorr_result<T>::observations() const
{
    size_t lvl = find_level(DEFAULT_MIN_SAMPLES);

    return level_[lvl].observations();
}
示例#13
0
column<typename autocorr_result<T>::var_type> autocorr_result<T>::stderror() const
{
    size_t lvl = find_level(DEFAULT_MIN_SAMPLES);

    return level_[lvl].stderror();
}
示例#14
0
double autocorr_result<T>::count2() const
{
    size_t lvl = find_level(DEFAULT_MIN_SAMPLES);

    return level_[lvl].count2();
}