void CqImageBuffer::RepostSurface(const CqBucket& oldBucket, const boost::shared_ptr<CqSurface>& surface) { const CqBound rasterBound = surface->GetCachedRasterBound(); bool wasPosted = false; // Surface is behind everying in this bucket but it may be visible in other // buckets it overlaps. // // First look in bucket to the right TqInt nextBucketX = oldBucket.getCol() + 1; TqInt nextBucketY = oldBucket.getRow(); TqInt xpos = oldBucket.getXPosition() + oldBucket.getXSize(); if ( nextBucketX < m_bucketRegion.xMax() && rasterBound.vecMax().x() >= xpos ) { Bucket( nextBucketX, nextBucketY ).AddGPrim( surface ); wasPosted = true; } else { // next row ++nextBucketY; // find bucket containing left side of bound nextBucketX = max<TqInt>(m_bucketRegion.xMin(), lfloor(rasterBound.vecMin().x())/m_optCache.xBucketSize); TqInt ypos = oldBucket.getYPosition() + oldBucket.getYSize(); if ( ( nextBucketX < m_bucketRegion.xMax() ) && ( nextBucketY < m_bucketRegion.yMax() ) && ( rasterBound.vecMax().y() >= ypos ) ) { Bucket( nextBucketX, nextBucketY ).AddGPrim( surface ); wasPosted = true; } } #ifdef DEBUG // Print info about reposting. This is protected by DEBUG so that scenes // with huge amounts of occlusion won't silently be causing *heaps* of // logging traffic. CqString objName("unnamed"); if(const CqString* name = surface->pAttributes() ->GetStringAttribute("identifier", "name")) objName = name[0]; if(wasPosted) { Aqsis::log() << info << "GPrim: \"" << objName << "\" occluded in bucket: " << oldBucket.getCol() << ", " << oldBucket.getRow() << " shifted into bucket: " << nextBucketX << ", " << nextBucketY << "\n"; } else { Aqsis::log() << info << "GPrim: \"" << objName << "\" occlusion culled" << std::endl; } #endif }
void AudioProcAnalyzePitch(int16_t * samples, uint8_t gain, int16_t ** raw_buckets, int16_t ** full_buckets, int16_t ** octave_buckets) { // Apply a window. VectorWindow(ANALOG_BUFFER_LEN, samples, samples, window); // Apply gain and convert to complex. for (unsigned i = 0; i < ANALOG_BUFFER_LEN; ++i) { complex_buf[i].real = samples[i] * gain; complex_buf[i].imag = 0; } // In-place FFT. FFTComplexIP(ANALOG_LOG2_BUFFER_LEN, complex_buf, twiddle, COEFFS_IN_DATA); BitReverseComplex(ANALOG_LOG2_BUFFER_LEN, complex_buf); // Compute magnitude (first half of the buffer). SquareMagnitudeCplx(ANALOG_BUFFER_LEN / 2, complex_buf, samples); // Harmonic suppression. for (int i = ANALOG_BUFFER_LEN / 2 - 1; i >= 0; --i) { samples[i] -= samples[i / 2] / 2; if (samples[i] < 0) samples[i] = 0; } // Apply bucketing. *raw_buckets = samples + ANALOG_BUFFER_LEN / 2; *full_buckets = *raw_buckets + PITCH_COUNT; *octave_buckets = *full_buckets + BUCKET_COUNT; Bucket(samples, *raw_buckets, *full_buckets, *octave_buckets); }
/// Add a new sieving prime to EratSmall void EratSmall::storeSievingPrime(uint_t prime, uint_t multipleIndex, uint_t wheelIndex) { assert(prime <= limit_); uint_t sievingPrime = prime / NUMBERS_PER_BYTE; if (!buckets_.back().store(sievingPrime, multipleIndex, wheelIndex)) buckets_.push_back(Bucket()); }
std::vector<std::string> anagrams(std::vector<std::string> &strs) { std::map<int, std::vector<Bucket> > buckets; for (size_t i = 0; i < strs.size(); ++i) { std::vector<int> key = this->calcKey(strs[i]); int hash = this->calcHash(key); std::vector<Bucket> &bucket(buckets[hash]); bool ok = false; for (size_t j = 0; j < bucket.size(); ++j) { Bucket &bk(bucket[j]); if (ok = this->equal(bk.key, key)) { bk.val.push_back(strs[i]); break; } } if (!ok) { bucket.push_back(Bucket()); bucket.back().key = key; bucket.back().val.push_back(strs[i]); } } std::vector<std::string> result; for (std::map<int, std::vector<Bucket> >::const_iterator iter = buckets.begin(); iter != buckets.end(); ++iter) { const std::vector<Bucket> &bucket(iter->second); for (size_t j = 0; j < bucket.size(); ++j) { const Bucket &bk(bucket[j]); if (bk.val.size() > 1) std::copy(bk.val.begin(), bk.val.end(), std::back_inserter(result)); } } return (result); }
void StatFile::flushOneExpBucket() { // flush the bucket being shifted out, but nothing else Bucket &eb0(expBucket[0]); Log(LL_Debug, "istat") << "StatFile::flushOneExpBucket()" << eb0.time(); if (eb0.time() > 0) { int64_t ix = mapTimeToBucketIndex(eb0.time()); int64_t oix = mapTimeToBucketIndex(eb0.time() - fileHeader_->season); Bucket *wb = writableBucket(ix); Bucket const &o = bucket(oix); if (o.time() > 0) { *wb = o; wb->expUpdate(eb0, fileHeader_->lambda); } else { *wb = eb0; } } // must move one over memmove(expBucket, &expBucket[1], sizeof(expBucket)-sizeof(expBucket[0])); expBucket[sizeof(expBucket)/sizeof(expBucket[0])-1] = Bucket(true); }
void BucketTest::testOperators() { CPPUNIT_ASSERT(BucketSpace(0x1) == BucketSpace(0x1)); CPPUNIT_ASSERT(BucketSpace(0x1) != BucketSpace(0x2)); CPPUNIT_ASSERT(BucketSpace(0x1) < BucketSpace(0x2)); CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) == Bucket(BucketSpace(0x1), BucketId(0x123456789ULL))); CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) != Bucket(BucketSpace(0x2), BucketId(0x123456789ULL))); CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) != Bucket(BucketSpace(0x1), BucketId(0x987654321ULL))); CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) < Bucket(BucketSpace(0x1), BucketId(0x987654321ULL))); CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) < Bucket(BucketSpace(0x2), BucketId(0x123456789ULL))); }
bucket_sorter(size_type _length, bucket_type _max_bucket, const Bucket& _bucket = Bucket(), const ValueIndexMap& _id = ValueIndexMap()) : head(_max_bucket, invalid_value()), next(_length, invalid_value()), prev(_length, invalid_value()), id_to_value(_length), bucket(_bucket), id(_id) { }
/// @param stop Upper bound for sieving. /// @param sieveSize Sieve size in bytes. /// @param limit Sieving primes in EratSmall must be <= limit. /// EratSmall::EratSmall(uint64_t stop, uint_t sieveSize, uint_t limit) : Modulo30Wheel_t(stop, sieveSize), limit_(limit) { if (limit > sieveSize * 3) throw primesieve_error("EratSmall: limit must be <= sieveSize * 3"); buckets_.push_back(Bucket()); }
Bucket Bucket::operator/(int size) { Bucket newBucket = Bucket(this->owner); for (int i = 0; i < this->elementsCount; i++) newBucket.addEgg(Egg(this->container[i].getName, this->container[i].getSize / size)); return newBucket; }
FifoBucketOrder::FifoBucketOrder(const unsigned int width, const unsigned int height, const unsigned int size) : BucketOrder(width, height, size) { unsigned int sqSize = 1 << size; unsigned int completeWidth = width/sqSize; unsigned int fragmentWidth = width%sqSize; unsigned int completeHeight = height/sqSize; unsigned int fragmentHeight = height%sqSize; unsigned int x=0; unsigned int y=0; for (y=0; y<completeHeight; y++) { for (x=0; x<completeWidth; x++) { Bucket b(x*sqSize, y*sqSize, x*sqSize+sqSize-1, y*sqSize+sqSize-1); m_buckets.push_back(b); } if (fragmentWidth) { m_buckets.push_back(Bucket(x*sqSize, y*sqSize, x*sqSize+fragmentWidth-1, y*sqSize+sqSize-1)); } } if (fragmentHeight) { for (x=0; x<completeWidth; x++) { m_buckets.push_back(Bucket(x*sqSize, y*sqSize, x*sqSize+sqSize-1, y*sqSize+fragmentHeight-1)); } if (fragmentWidth) { m_buckets.push_back(Bucket(x*sqSize, y*sqSize, x*sqSize+fragmentWidth-1, y*sqSize+fragmentHeight-1)); } } }
/// @param stop Upper bound for sieving. /// @param sieveSize Sieve size in bytes. /// @param limit Sieving primes in EratMedium must be <= limit. /// EratMedium::EratMedium(uint64_t stop, uint_t sieveSize, uint_t limit) : Modulo210Wheel_t(stop, sieveSize), limit_(limit) { // ensure multipleIndex < 2^23 in crossOff() if (sieveSize > (1u << 21)) throw primesieve_error("EratMedium: sieveSize must be <= 2^21, 2048 kilobytes"); if (limit > sieveSize * 9) throw primesieve_error("EratMedium: limit must be <= sieveSize * 9"); buckets_.push_back(Bucket()); }
void OpticalFlow::buildBuckets(double initial_distance, double max_distance, int angle_buckets){ double increment = 360.0/angle_buckets; double last_angle = 0.0; double last_distance = 0.0; for(double a = increment; a <= 360.0; a+=increment){ for(double d = initial_distance; d <= max_distance; d+= initial_distance){ buckets.push_back(Bucket(last_distance, d, last_angle, a)); last_distance = d; } last_angle = a; } }
void create_bucket(void) { PackedValuePoolBase::Slot s; s.m_bucket = m_data.size(); m_data.push_back(FASTUIDRAWnew Bucket()); for (int i = Bucket::array_size - 1; i >=0; --i) { s.m_element_of_bucket = i; this->m_free_slots.push_back(s); } }
Bucket *StatFile::getTrailingBucket(time_t time) { size_t n = sizeof(expBucket)/sizeof(expBucket[0]); for (size_t i = 0; i != n; ++i) { if (expBucket[i].time() == time) { return &expBucket[i]; } } // maybe flush to disk -- also, shift buckets over one flushOneExpBucket(); expBucket[n-1] = Bucket(0, 0, 0, 0, 0, time); return &expBucket[n-1]; }
Bucket & Bucket::operator%=(const Bucket & rhs) { Bucket newBucket = Bucket(); for (size_t i = 0; i < this->elementsCount; i++) { for (size_t j = 0; j < rhs.getElementsCount(); j++) { if (this->container[i] == rhs.getContainer()[j]) newBucket.addEgg(this->container[i]); } } *this = newBucket; return *this; }
/** * Initializes some core values, hash functions and buckets. */ void SplashTable::init(){ noOfBuckets = exp2(S)/B; //Since B is a power of 2 totalCount = 0; //Initializes buckets with bucketsize B for(int i = 0; i<noOfBuckets; i++){ buckets.push_back(Bucket(B)); } srand( time(0)); //Initialize all hash functions with random multiplier for(int i = 0; i<h; i++){ uint r = getRandom(0,UINT_MAX-1); hashes.push_back(MHash(r,S,B)); } }
void* AdultHeap::allocate(size_t sz, GarbageHeader*& header) { const size_t header_padding = 0x10 - sizeof(GarbageHeader) % 0x10; size_t required_size = sizeof(GarbageHeader) + header_padding + sz; // align required_size += (0x10 - required_size % 0x10); void* object = NULL; #pragma omp critical { std::list<Bucket>::iterator free_bucket_iter = m_Buckets.end(); for each (iter, m_Buckets) { if (iter->available() >= required_size) { free_bucket_iter = iter.iterator(); break; } } if (free_bucket_iter == m_Buckets.end()) { // No buckets with free space... Make a new one free_bucket_iter = m_Buckets.insert(m_Buckets.begin(), Bucket()); size_t size = required_size > ADULT_HEAP_STANDARD_BUCKET_SIZE ? required_size : ADULT_HEAP_STANDARD_BUCKET_SIZE; free_bucket_iter->data = new(kMalloc) byte[size]; free_bucket_iter->size = size; free_bucket_iter->offset = 0; } Bucket* bucket = &*free_bucket_iter; header = reinterpret_cast<GarbageHeader*>(&bucket->data[bucket->offset]); object = &bucket->data[bucket->offset + sizeof(GarbageHeader) + header_padding]; bucket->offset += required_size; } header->size = required_size - (sizeof(GarbageHeader) + header_padding); header->flags = GC_NO_FLAGS; header->generation = 0; header->free_func = NULL; return object; }
void CqImageBuffer::AddMPG( boost::shared_ptr<CqMicroPolygon>& pmpgNew ) { CqRenderer* renderContext = QGetRenderContext(); CqBound B = pmpgNew->GetBound(); // Expand the micropolygon bound for DoF if necessary. if(renderContext->UsingDepthOfField()) { // Get the maximum CoC multiplier for the micropolygon depth. const CqVector2D maxCoC = max( renderContext->GetCircleOfConfusion(B.vecMin().z()), renderContext->GetCircleOfConfusion(B.vecMax().z()) ); // Expand the bound by the CoC radius B.vecMin() -= vectorCast<CqVector3D>(maxCoC); B.vecMax() += vectorCast<CqVector3D>(maxCoC); } // Discard when outside the crop window. if ( B.vecMax().x() < renderContext->cropWindowXMin() - m_optCache.xFiltSize / 2.0f || B.vecMax().y() < renderContext->cropWindowYMin() - m_optCache.yFiltSize / 2.0f || B.vecMin().x() > renderContext->cropWindowXMax() + m_optCache.xFiltSize / 2.0f || B.vecMin().y() > renderContext->cropWindowYMax() + m_optCache.yFiltSize / 2.0f ) { return; } ////////// Dump the micro polygon into a dump file ////////// #if ENABLE_MPDUMP if(m_mpdump.IsOpen()) m_mpdump.dump(*pmpgNew); #endif ///////////////////////////////////////////////////////////// // Find out the minimum bucket touched by the micropoly bound. B.vecMin().x( B.vecMin().x() - (lfloor(m_optCache.xFiltSize / 2.0f)) ); B.vecMin().y( B.vecMin().y() - (lfloor(m_optCache.yFiltSize / 2.0f)) ); B.vecMax().x( B.vecMax().x() + (lfloor(m_optCache.xFiltSize / 2.0f)) ); B.vecMax().y( B.vecMax().y() + (lfloor(m_optCache.yFiltSize / 2.0f)) ); TqInt iXBa = static_cast<TqInt>( B.vecMin().x() / m_optCache.xBucketSize ); TqInt iYBa = static_cast<TqInt>( B.vecMin().y() / m_optCache.yBucketSize ); TqInt iXBb = static_cast<TqInt>( B.vecMax().x() / m_optCache.xBucketSize ); TqInt iYBb = static_cast<TqInt>( B.vecMax().y() / m_optCache.yBucketSize ); if ( ( iXBb < m_bucketRegion.xMin() ) || ( iYBb < m_bucketRegion.yMin() ) || ( iXBa >= m_bucketRegion.xMax() ) || ( iYBa >= m_bucketRegion.yMax() ) ) { return ; } // Use sane values -- otherwise sometimes crashes, probably // due to precision problems if ( iXBa < m_bucketRegion.xMin() ) iXBa = m_bucketRegion.xMin(); if ( iYBa < m_bucketRegion.yMin() ) iYBa = m_bucketRegion.yMin(); if ( iXBb >= m_bucketRegion.xMax() ) iXBb = m_bucketRegion.xMax() - 1; if ( iYBb >= m_bucketRegion.yMax() ) iYBb = m_bucketRegion.yMax() - 1; // Add the MP to all the Buckets that it touches for ( TqInt i = iXBa; i <= iXBb; i++ ) { for ( TqInt j = iYBa; j <= iYBb; j++ ) { CqBucket* bucket = &Bucket( i, j ); // Only add the MPG if the bucket isn't processed. // \note It is possible for this to happen validly, if a primitive is occlusion culled in a // previous bucket, and not in a subsequent one. When it gets processed in the later bucket // the MPGs can leak into the previous one, shouldn't be a problem, as the occlusion culling // means the MPGs shouldn't be rendered in that bucket anyway. if ( !bucket->IsProcessed() ) { bucket->AddMP( pmpgNew ); } } } }
void CqImageBuffer::PostSurface( const boost::shared_ptr<CqSurface>& pSurface ) { AQSIS_TIME_SCOPE(Post_surface); // Count the number of total gprims STATS_INC( GPR_created_total ); // Bound the primitive in its current space (camera) space taking into account any motion specification. CqBound Bound; pSurface->Bound(&Bound); // Take into account the displacement bound extension. TqFloat db = 0.0f; CqString strCoordinateSystem( "object" ); const TqFloat* pattrDispclacementBound = pSurface->pAttributes() ->GetFloatAttribute( "displacementbound", "sphere" ); const CqString* pattrCoordinateSystem = pSurface->pAttributes() ->GetStringAttribute( "displacementbound", "coordinatesystem" ); if ( pattrDispclacementBound != 0 ) db = pattrDispclacementBound[ 0 ]; if ( pattrCoordinateSystem != 0 ) strCoordinateSystem = pattrCoordinateSystem[ 0 ]; if ( db != 0.0f ) { CqVector3D vecDB( db, 0, 0 ); const IqTransform* transShaderToWorld = NULL; // Default "shader" space to the displacement shader, unless there isn't one, in which // case use the surface shader. if ( pSurface->pAttributes() ->pshadDisplacement(QGetRenderContextI()->Time()) ) transShaderToWorld = pSurface->pAttributes() ->pshadDisplacement(QGetRenderContextI()->Time()) ->getTransform(); else if ( pSurface->pAttributes() ->pshadSurface(QGetRenderContextI()->Time()) ) transShaderToWorld = pSurface->pAttributes() ->pshadSurface(QGetRenderContextI()->Time()) ->getTransform(); CqMatrix mat; QGetRenderContext() ->matVSpaceToSpace( strCoordinateSystem.c_str(), "camera", transShaderToWorld, pSurface->pTransform().get(), QGetRenderContextI()->Time(), mat ); vecDB = mat * vecDB; db = vecDB.Magnitude(); Bound.vecMax() += db; Bound.vecMin() -= db; } // Check if the surface can be culled. (also adjusts for DOF and converts Bound to raster space). if ( CullSurface( Bound, pSurface ) ) { STATS_INC( GPR_culled ); return ; } // If the primitive has been marked as undiceable by the eyeplane check, then we cannot get a valid // bucket index from it as the projection of the bound would cross the camera plane and therefore give a false // result, so just put it back in the current bucket for further splitting. TqInt XMinb = 0; TqInt YMinb = 0; TqInt XMaxb = 0; TqInt YMaxb = 0; if (! pSurface->IsUndiceable() ) { XMinb = static_cast<TqInt>( Bound.vecMin().x() ) / m_optCache.xBucketSize; YMinb = static_cast<TqInt>( Bound.vecMin().y() ) / m_optCache.yBucketSize; XMaxb = static_cast<TqInt>( Bound.vecMax().x() ) / m_optCache.xBucketSize; YMaxb = static_cast<TqInt>( Bound.vecMax().y() ) / m_optCache.yBucketSize; } XMinb = clamp( XMinb, m_bucketRegion.xMin(), m_bucketRegion.xMax()-1 ); YMinb = clamp( YMinb, m_bucketRegion.yMin(), m_bucketRegion.yMax()-1 ); XMaxb = clamp( XMaxb, m_bucketRegion.xMin(), m_bucketRegion.xMax()-1 ); YMaxb = clamp( YMaxb, m_bucketRegion.yMin(), m_bucketRegion.yMax()-1 ); // Sanity check we are not putting into a bucket that has already been processed. CqBucket* bucket = &Bucket( XMinb, YMinb ); if ( bucket->IsProcessed() ) { // Scan over the buckets that the bound touches, looking for the first one that isn't processed. TqInt yb = YMinb; TqInt xb = XMinb + 1; bool done = false; while(!done && yb <= YMaxb) { while(!done && xb <= XMaxb) { CqBucket& availBucket = Bucket(xb, yb); if(!availBucket.IsProcessed()) { availBucket.AddGPrim(pSurface); done = true; } ++xb; } xb = XMinb; ++yb; } } else { bucket->AddGPrim( pSurface ); } }
int RingBuf::Dist(int indexB, int indexE) const { return Since(Bucket(indexB), Bucket(indexE)); }
void *RingBuf::Read(int index, int Next) const { Next = Next>=0 ? Next : ring.back; int ind = Bucket(Next+index); return (void *)(buf + ind * width); }
Factor_Data::Factor_Data (int key) : Class_Index (key) { Factor (0.0); Bucket (0.45); }
void SortedDeque<T, TSize>::addBucket() { deque.push_back(Bucket()); }
microseconds RingBuf::ReadTimestamp(int index, int Next) const { Next = Next>=0 ? Next : ring.back; int ind = Bucket(Next+index); return stamp[ind]; }