void CaseInsensitiveHashTable<T>::reset(size_t capacity) { size_t index_capacity = next_pow_2(static_cast<size_t>(capacity / CASS_LOAD_FACTOR) + 1); std::fill(index_.begin(), index_.end(), static_cast<T*>(NULL)); // Clear the old entries index_.resize(index_capacity); entries_.reserve(capacity); index_mask_ = index_capacity - 1; }
int fft_to_time_domain(complex *dft_input, complex **output, const unsigned int length) { unsigned int bits, i; assert(dft_input != NULL && length == next_pow_2(length)); *output = (complex *)calloc(length, sizeof(complex)); if(!(*output)) { return 1; //calloc failed } for(bits = 0; (length - 1)>>bits; ++bits); if(fft_iterative(dft_input, *output, bits, 1)) //to time domain { free(*output); *output = NULL; return 1; } for(i = 0; i < length; ++i) { (*output)[i].Re /= length; (*output)[i].Im /= length; } return 0; }
L wrapList(I l, V* v) { I c=next_pow_2(l); T t=0; DO(i,l)t|=T(v[i]); if(PURE(t)){ I s=t_sizeof(t); P p=MALLOC(c*s); DO(i,l) { memcpy(p+i*s, P(v[i]), s); FREE(P(v[i])); } L r=wrapL(t,c,l,0,p); FREE(v); return r; } else {
MPMCQueue(size_t size) : size_(next_pow_2(size)) , mask_(size_ - 1) , buffer_(new Node[size_]) , tail_(0) , head_(0) { // populate the sequence initial values for (size_t i = 0; i < size_; ++i) { buffer_[i].seq.store(i, MEMORY_ORDER_RELAXED); } }
// Turn v into a modifiable list including type t. void addtype(V v, T t) { L l=L(v); T lt=l->t; if (lt&t || IMPURE(lt)) get(v); else { I n=l->l, c=next_pow_2(n), s=t_sizeof(lt); DECL_ARR(V,vs,c); DO(i,n) { vs[i] = cpy1(list_ats(l,i,s)); } if (l->r<=1) { FREE(l->p); l->r=1; l->t|=t; l->c=c; l->o=0; l->p=(P)vs; } else { l->r--; L(v) = wrapL(lt|t, c, n, 0, vs); } }
// drop a elements from the beginning and b from the end of l void cropList(V p, V l, I a, I b) { L lv=L(l); if (lv->r > 1) { I nl=lv->l-a-b; T t=lv->t; I s=t_sizeof(t); P v=MALLOC(s*next_pow_2(nl)); DO(i,nl) valcpy(v+s*i, LIST_PTR_ATS(lv,i+a,s), t); del(l); setL(p, wrapArray(t, nl, v)); } else { if (a>0) { DO(j,a) del(list_at(lv,a)); } if (b>0) { DO(j,b) del(list_at(lv,lv->l-b+j)); } lv->o = (lv->o+a) % lv->c; lv->l -= a+b; mv_P(p, l); } }
static void *add_page(struct block *block) { if (block->count == next_pow_2(block->count)) { size_t new_size = (size_t)(block->count * 2); void **pages = realloc(block->pages, sizeof(*pages) * new_size); if (!pages) return NULL; block->pages = pages; } void *page = alloc_page(); if (!page) return NULL; return block->pages[block->count++] = page; }
int fft_to_frequency_domain(complex **input, complex **fft, const unsigned int length) { complex *tmp; unsigned int bits, next_pow_2_num, i; assert(*input != NULL); next_pow_2_num = next_pow_2(length); if(next_pow_2_num != length) { tmp = (complex *)realloc(*input, next_pow_2_num * sizeof(complex)); if(tmp == NULL) { return -1; //memory reallocation failed } else { *input = tmp; for(i = length; i < next_pow_2_num; ++i) { (*input)[i].Re = 0; (*input)[i].Im = 0; } } } *fft = (complex *)calloc(next_pow_2_num, sizeof(complex)); if(*fft == NULL) { return -1; //memory allocation failed } for(bits = 0; (next_pow_2_num - 1)>>bits; ++bits); if(fft_iterative(*input, *fft, bits, 0)) //to freq domain { free(*fft); *fft = NULL; return -1; //fft_iterative failed } return 0; }
KOKKOS_INLINE_FUNCTION ValueType team_reduce( const ValueType & value , const JoinOp & op_in) const { typedef JoinLambdaAdapter<ValueType,JoinOp> JoinOpFunctor ; const JoinOpFunctor op(op_in); const auto local = idx.local[0]; tile_static ValueType buffer[128]; const std::size_t size = next_pow_2(m_team_size+1)/2; lds_for(buffer[local], [&](ValueType& x) { x = value; }); idx.barrier.wait(); for(std::size_t s = 1; s < size; s *= 2) { const std::size_t index = 2 * s * local; if (index < size) { lds_for(buffer[index], [&](ValueType& x) { lds_for(buffer[index+s], [&](ValueType& y) { op.join(x, y); }); }); } idx.barrier.wait(); } if (local == 0) { buffer[0] = std::accumulate(buffer+size, buffer+m_team_size, buffer[0], [&](ValueType x, ValueType y) { op.join(x, y); return x; }); } idx.barrier.wait(); return buffer[0]; }
// structures! w = sketch_width(s->sketch); d = sketch_depth(s->sketch); hh->logm = logm; hh->params = params; hh->norm = 0; hh->result.count = 0; hh->fifo = fifo_create(twophi); hh->result.size = twophi; hh->result.hitters = xmalloc( result_size ); memset(hh->result.hitters, '\0', result_size); // Find the base (log2) of the next power of two of w*d np2_base = MultiplyDeBruijnBitPosition2[ (uint32_t)(next_pow_2(w*d) * 0x077CB531U) >> 27 ]; //+ 1; We only do exact when it is below size of sketch if (np2_base > logm) { np2_base = logm; } top_tree_size = sizeof(uint64_t) * ((1 << (np2_base+1))-2); hh->top = xmalloc( top_tree_size ); memset(hh->top, '\0', top_tree_size ); hh->top_cnt = np2_base; if ( np2_base < logm ) { hh->tree = xmalloc( sizeof(sketch_t *) * (logm-np2_base) ); for (i = 0; i < (logm-1)-np2_base; i++) { hh->tree[i] = sketch_create(params->f, p->hash, b, epsilon, delta);
SPSCQueue(size_t size) : size_(next_pow_2(size)) , mask_(size_ - 1) , buffer_(new T[size_]) , tail_(0) , head_(0) {}
// Custom wrap functions L wrapArray(T t, I l, P p) { I c=next_pow_2(l); p=realloc(p, c*t_sizeof(t)); return wrapL(t,c,l,0,p); }