void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src, grpc_chttp2_stream_map *dst) { /* if src is empty we dont need to do anything */ if (src->count == src->free) { return; } /* if dst is empty we simply need to swap */ if (dst->count == dst->free) { GPR_SWAP(grpc_chttp2_stream_map, *src, *dst); return; } /* the first element of src must be greater than the last of dst... * however the maps may need compacting for this property to hold */ if (src->keys[0] <= dst->keys[dst->count - 1]) { src->count = compact(src->keys, src->values, src->count); src->free = 0; dst->count = compact(dst->keys, dst->values, dst->count); dst->free = 0; } GPR_ASSERT(src->keys[0] > dst->keys[dst->count - 1]); /* if dst doesn't have capacity, resize */ if (dst->count + src->count > dst->capacity) { dst->capacity = GPR_MAX(dst->capacity * 3 / 2, dst->count + src->count); dst->keys = gpr_realloc(dst->keys, dst->capacity * sizeof(uint32_t)); dst->values = gpr_realloc(dst->values, dst->capacity * sizeof(void *)); } memcpy(dst->keys + dst->count, src->keys, src->count * sizeof(uint32_t)); memcpy(dst->values + dst->count, src->values, src->count * sizeof(void *)); dst->count += src->count; dst->free += src->free; src->count = 0; src->free = 0; }
static int join_leaf ( tree_s *tree, branch_s *parent, leaf_s *child, int k) { leaf_s *sibling; sibling = bget(tree->t_dev, parent->br_key[k+1].k_block); if (!sibling) return qERR_NOT_FOUND; if (child->l_total + sibling->l_total > MAX_FREE) { FN; compact(child); compact(sibling); copy_recs(child, sibling, 0); memmove( &parent->br_key[k+1], &parent->br_key[k+2], sizeof(parent->br_key[0]) * (parent->br_num - (k+2))); --parent->br_num; bdirty(parent); } //verify_leaf(child, WHERE); bput(sibling); // Should free sibling return 0; }
Array f_compact(int _argc, CVarRef varname, CArrRef _argv /* = null_array */) { Array ret = Array::Create(); HPHP::VM::VarEnv* v = g_vmContext->getVarEnv(); if (v) { compact(v, ret, varname); compact(v, ret, _argv); } return ret; }
void garbage_collect() { mark_all_cells(); unmark_cells(all_symbols, all_symbols, 0); unmark_cells(top_env, top_env, 0); reclaim_marked(); update_remaining(); compact(all_symbols); compact(top_env); top_allocated = NULL; }
void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, uint32_t key, void *value) { size_t count = map->count; size_t capacity = map->capacity; uint32_t *keys = map->keys; void **values = map->values; GPR_ASSERT(count == 0 || keys[count - 1] < key); GPR_ASSERT(value); GPR_ASSERT(grpc_chttp2_stream_map_find(map, key) == NULL); if (count == capacity) { if (map->free > capacity / 4) { count = compact(keys, values, count); map->free = 0; } else { /* resize when less than 25% of the table is free, because compaction won't help much */ map->capacity = capacity = 3 * capacity / 2; map->keys = keys = gpr_realloc(keys, capacity * sizeof(uint32_t)); map->values = values = gpr_realloc(values, capacity * sizeof(void *)); } } keys[count] = key; values[count] = value; map->count = count + 1; }
int main() { read(); sort(); compact(); write(); return 0; }
int CStreamBuffer::write( int sd, int flag ) { int res = 0; char* p = m_buffer + m_offset; size_t len = m_used - m_offset; while( len > 0 ){ WRAP_SYSCALL( res, send( sd, p, len, flag ) ); if( res < 0 ){ if( errno == EAGAIN || errno == EWOULDBLOCK ){ perror( "not ready yet" ); return ERR_SEND_FAILED; } else{ perror( "couldn't send" ); return -1; } } len -= res; p += res; m_offset += res; } compact( m_offset ); return 0; }
// compact: compact repeat instructions static instruction *compact (instruction *prog) { instruction *ret = prog; register char flag1 = 0, flag2 = 0; while (prog) { switch ((int) prog->opcode) { case LOOP_START: prog->loop = compact(prog->loop); break; case INC: case DEC: case NEXT: case PREV: flag1 = flag2 = 0; while (prog->next && (flag1 = same(prog) || (flag2 = another(prog)))) { instruction *t = prog->next; prog->value += flag1 && !flag2 ? t->value : -t->value; prog->next = t->next; free(t); } break; } prog = prog->next; } return ret; }
void i4_horizontal_compact_window_class::receive_event(i4_event * ev) { if (ev->type()==i4_event::WINDOW_MESSAGE) { CAST_PTR(mess,i4_window_message_class,ev); if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE) { CAST_PTR(res,i4_window_notify_resize_class,ev); sw32 ow=res->from()->width(), oh=res->from()->height(); res->from()->private_resize(res->new_width, res->new_height); compact(); res->from()->private_resize(ow, oh); note_undrawn(0,0, width()-1, height()-1); } else { i4_parent_window_class::receive_event(ev); } } else { i4_parent_window_class::receive_event(ev); } }
void Server::aggregate (const std::string & survey_in) { Structure survey; survey.load(survey_in); if (POMAGMA_DEBUG_LEVEL > 1) { survey.validate(); } compact(m_structure); if (POMAGMA_DEBUG_LEVEL > 1) { m_structure.validate(); } DenseSet defined = restricted(survey.signature(), m_structure.signature()); size_t total_dim = m_structure.carrier().item_count() + defined.count_items(); if (m_structure.carrier().item_dim() < total_dim) { m_structure.resize(total_dim); if (POMAGMA_DEBUG_LEVEL > 1) { m_structure.validate(); } } pomagma::aggregate(m_structure, survey, defined); if (POMAGMA_DEBUG_LEVEL > 1) { m_structure.validate(); } }
void try_compact() { if (arena != 0 && freemem != 0) { struct myinfo stat = myinfo(); double fragm = ((double)(stat.freemem - stat.maxfreeblk) * 100) / stat.freemem; if (fragm > 70) compact(); } }
int main(){ std::cout<<"main started mmStart"<<&M<<std::endl; assert0(chdir("/home/gk/Dropbox/workspace01/napl22")==0,"unable to change dir"); stopETs.store(false,0); ETs.reserve(0x100); compact(M); #if true int fin,i; if( (fin=open("naplStart0.napl",0,S_IRUSR))>=0){ i=startET(fin,dup(fileno(stdout))); } while(!ETs[i].threadEnded){} if(ETs[i].joinable()) ETs[i].join(); #endif HandleIncomingConnections(8000); for(size_t i=0;i<ETs.size();i++){ std::cout<<"ETs["<<i<<"] threadEnded="<<ETs[i].threadEnded<<" joinable="<<ETs[i].joinable()<<std::endl; if(ETs[i].joinable()) ETs[i].join(); } for(size_t i=0;i<ETs.size();i++){ std::cout<<"ETs["<<i<<"] threadEnded="<<ETs[i].threadEnded<<" joinable="<<ETs[i].joinable()<<std::endl; } return 0; }
void MA_compact(void) { MemBlk *mb; Header *fh, *mfh = NULL; int i; ENTERCRITICALSECTION(CS); for (mb=MMBP ; mb ; mb = mb->next) { fh = compact(mb); if (fh) { fh->next = mfh; mfh = fh; } } for (i=0 ; Map[i].userBytes ; ++i) Map[i].h = NULL; while (fh = mfh) { mfh = fh->next; fh->status = 'U'; fh->next = NULL; MA_free(fh+1); } LEAVECRITICALSECTION(CS); }
void Server::trim(const std::vector<TrimTask>& tasks) { compact(m_structure); const size_t item_count = m_structure.carrier().item_count(); std::vector<TrimTask> sorted_tasks = tasks; std::sort(sorted_tasks.begin(), sorted_tasks.end(), [](const TrimTask& lhs, const TrimTask& rhs) { return lhs.size > rhs.size; }); const size_t task_count = sorted_tasks.size(); #pragma omp parallel for schedule(dynamic, 1) for (size_t iter = 0; iter < task_count; ++iter) { const TrimTask& task = sorted_tasks[iter]; if (task.size >= item_count) { if (task.size > item_count) { POMAGMA_WARN("trimming only " << item_count << " of " << task.size << " obs"); } m_structure.dump(task.filename); } else { Structure region; region.init_carrier(task.size); extend(region.signature(), m_structure.signature()); pomagma::trim(m_structure, region, m_theory_file, m_language_file, task.temperature); if (POMAGMA_DEBUG_LEVEL > 1) { region.validate(); } region.dump(task.filename); } } }
/* * Remove -- remove an entry from this node * * */ void indexNode::remove(void *key, bSize_t len) { repOK(); TOUCH(); //find the index of the record corresponding to key int i=0; while ( (i < header->numElems) && (tree->comparisonFunction(key, len, nth_key(i), nth_keyLen(i))) ) i++; if (i == header->numElems) { warn("attempt to delete non-existent element (indexNode)"); exit(1); } //shuffle the localPointers for (int j = i; j < header->numElems - 1; j++) header->localPointers[j] = header->localPointers[j+1]; header->numElems--; repOK(); compact(); return; }
Error hmAlloc(Address* addressPtr, unsigned long int size) { HmEntry entry; size = size + (ALIGN - size % ALIGN); /* round up to multiple of words */ entry = start; *addressPtr = NULL; /*** here we enter a critical section */ lock(hmLock); /* try to find a free piece of memory */ entry = findFree(size); if (entry == NULL) { /* compact and try again */ compact(start); entry = findFree(size); } if (entry == NULL) { unlock( hmLock); return HM_ALLOCFAILED; } split(entry, size); *addressPtr = (Address)((unsigned long)entry + sizeof(HmEntryDesc)); unlock(hmLock); return HM_ALLOCOK; }
void PackageService::onFinish() { FinishSqliteVFS(); // Turn off all sticky flags - NO MERCY! for (PackageNameMap::iterator itr = _linkedPackages.begin(), end = _linkedPackages.end(); itr != end; ++itr) { itr->second->_stayResident = false; itr->second->_stayForCurrent = false; itr->second->_stayForNext = false; } // And compact so that all packages get disposed compact(); // If Something's remaining, we're in danger! for (PackageNameMap::iterator itr = _linkedPackages.begin(), end = _linkedPackages.end(); itr != end; ++itr) { Package* pack = itr->second; LOG(0, "*** Package '%s': still alive: %d usage, requires:\n", pack->getName().c_str(), pack->getUseCount()); if (pack->getRequiredList().empty()) LOG(0, " <none>\n"); else pack->printDependancy(1); } // Terminate AsyncLoader if (_asyncLoader) { _asyncLoader->Terminate(); } safeDelete(_asyncLoader); }
bool Zerobuf::_fromJSON( const std::string& string ) { if( !_allocator ) return true; Json::Value json; Json::Reader reader; if( !reader.parse( string, json )) { std::cerr << "Error parsing JSON: " << reader.getFormattedErrorMessages() << std::endl; return false; } try { _parseJSON( json ); } catch( const std::exception& e ) { std::cerr << "Error applying JSON: " << e.what() << std::endl; return false; } compact(); return true; }
/*! Replaces the item at index position \a i with \a value. \a i must be a valid index position in the array (i.e., \c{0 <= i < size()}). \sa operator[](), removeAt() */ void QJsonArray::replace(int i, const QJsonValue &value) { Q_ASSERT (a && i >= 0 && i < (int)(a->length)); QJsonValue val = value; bool compressed; int valueSize = QJsonPrivate::Value::requiredStorage(val, &compressed); detach(valueSize); if (!a->length) a->tableOffset = sizeof(QJsonPrivate::Array); int valueOffset = a->reserveSpace(valueSize, i, 1, true); if (!valueOffset) return; QJsonPrivate::Value &v = (*a)[i]; v.type = (val.t == QJsonValue::Undefined ? QJsonValue::Null : val.t); v.latinOrIntValue = compressed; v.latinKey = false; v.value = QJsonPrivate::Value::valueToStore(val, valueOffset); if (valueSize) QJsonPrivate::Value::copyData(val, (char *)a + valueOffset, compressed); ++d->compactionCounter; if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u) compact(); }
void Btree<T>::restore(Bstruct<T> *ptr, unsigned pos) // // // Purpose: locates an item and inserts into nodeLink[pos] of // node ptr in order to restore the minimum number of items in // the targeted node. // // Parameters: // // input: ptr - the pointer to the manipulated node // pos - the index of the inserted element // { Bstruct<T> *childBuf, *childBuf2; childBuf = new Bstruct<T>; if (pos == 0) { readNode(childBuf, ptr->nodeLink[1]); // restore leftmost element in the current node? if (childBuf->count > BTREE_MIN) shiftLeft(ptr, 1); else compact(ptr, 1); } // restore the rightmost element in the current node? else if (pos == ptr->count) { readNode(childBuf, ptr->nodeLink[pos - 1]); if (childBuf->count > BTREE_MIN) shiftRight(ptr, pos); else compact(ptr, pos); } // restore other internal elements in the current node else { childBuf2 = new Bstruct<T>; readNode(childBuf, ptr->nodeLink[pos - 1]); readNode(childBuf2, ptr->nodeLink[pos + 1]); if (childBuf->count > BTREE_MIN) shiftRight(ptr, pos); else if (childBuf2->count > BTREE_MIN) shiftLeft(ptr, pos + 1); else compact(ptr, pos); delete childBuf2; } delete childBuf; }
char* DynBlock::getPointer() const { if (!first) return NULL; if (first -> next) compact(); return (first -> data); }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: sparsebundle-compact SPARSEBUNDLE\n"); exit(-2); } compact(argv[1]); return 0; }
/** * Should be called when you know that ct.choose.cnt==1 * or ct.choose.cnt-1==0. This will logically remove this * entry from the array also taking care of repointing the * newTop to the correct position once ct is removed. After * length is decremented it is checked if compaction is needed * and if so, SUBSEQ_ALLOCS of memory is compacted. The removal * is simply a swap with the last element since the current count * is 1 and the items array is always sorted in descending order * and only has non-zero entries. Also all pointers to items * are going to be invalid if compaction runs successfully. * * ****** Be extra careful while using this ******* */ void TopicCounts::removeOldTop(topic_t ind, cnt_topic_t& ct) { if (length - 1 != 0) { cnt_topic_t tmp = ct; ct = items[length - 1]; items[length - 1] = tmp; } --length; compact(); }
void KMFolder::expireOldMessages( bool immediate ) { KMail::ScheduledExpireTask* task = new KMail::ScheduledExpireTask(this, immediate); kmkernel->jobScheduler()->registerTask( task ); if ( immediate ) { // #82259: compact after expiring. compact( CompactLater ); } }
void hsBitVector::write(hsStream* S) { #ifndef DEBUG // don't modify the written objects, we might want to compare them compact(); #endif S->writeInt(fNumVectors); for (size_t i=0; i<fNumVectors; i++) S->writeInt(fBits[i]); }
void* internal_allocate(size_t size) { void* ptr = get_block(alloc_align(size)); if (ptr == NULL) { compact(); ptr = get_block(alloc_align(size)); } try_compact(); return ptr; }
/* * insert - This function blindly inserts the item which it assumes * consists of a key/pointer pair into the appropriate place * in the node. This will only be called by split() and split() * is required to juggle the pointers */ void indexNode::insert(record *item, int policy, callback<void, int>::ref cb) { void *key; bSize_t keyLen; void *value; bSize_t valLen; bSize_t totalLen; indexElemRep *elem; int i=0, keyLoc; repOK(); TOUCH(); //extract the data from the record value = item->getValue(&valLen); key = item->getKey(&keyLen); if (valLen != sizeof(nodeID_t)) { fatal("bad index record format"); } totalLen = keyLen + sizeof(indexElemRep); if (splitRequired(totalLen)) { split(item, cb); return; } repOK(); compact(); //fill in the record elem = (indexElemRep *)(bottomOfFreeSpace - totalLen); elem->p = *((nodeID_t *)value); //the only thing this can be is a nodeID_t * elem->keyLen = keyLen; memcpy(&(elem->key[0]), key, keyLen); //find the place to insert (items are in ascending order) keyLoc = locateKey(key, keyLen); //insert it for (i = header->numElems; i > keyLoc; i--) header->localPointers[i] = header->localPointers[i-1]; bottomOfFreeSpace -= totalLen; int tmp = (bottomOfFreeSpace - (char *)data->base()); header->localPointers[keyLoc] = tmp; //update the header header->dataSize += totalLen; header->numElems++; repOK(); //success (*cb)(0); return; }
void *grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map *map) { if (map->count == map->free) { return NULL; } if (map->free != 0) { map->count = compact(map->keys, map->values, map->count); map->free = 0; } return map->values[((size_t)rand()) % map->count]; }
virtual bool run(const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string coll = cmdObj.firstElement().valuestr(); if( coll.empty() || db.empty() ) { errmsg = "no collection name specified"; return false; } if( isCurrentlyAReplSetPrimary() && !cmdObj["force"].trueValue() ) { errmsg = "will not run compact on an active replica set primary as this is a slow blocking operation. use force:true to force"; return false; } string ns = db + '.' + coll; if ( ! NamespaceString::normal(ns.c_str()) ) { errmsg = "bad namespace name"; return false; } // parameter validation to avoid triggering assertions in compact() if ( str::contains(ns, ".system.") ) { errmsg = "can't compact a system namespace"; return false; } { writelock lk; Client::Context ctx(ns); NamespaceDetails *d = nsdetails(ns.c_str()); if( ! d ) { errmsg = "namespace does not exist"; return false; } if ( d->capped ) { errmsg = "cannot compact a capped collection"; return false; } } double pf = 1.0; int pb = 0; if( cmdObj.hasElement("paddingFactor") ) { pf = cmdObj["paddingFactor"].Number(); assert( pf >= 1.0 && pf <= 4.0 ); } if( cmdObj.hasElement("paddingBytes") ) { pb = (int) cmdObj["paddingBytes"].Number(); assert( pb >= 0 && pb <= 1024 * 1024 ); } bool validate = !cmdObj.hasElement("validate") || cmdObj["validate"].trueValue(); // default is true at the moment bool ok = compact(ns, errmsg, validate, result, pf, pb); return ok; }
/*! Removes the value at index position \a i. \a i must be a valid index position in the array (i.e., \c{0 <= i < size()}). \sa insert(), replace() */ void QJsonArray::removeAt(int i) { if (!a || i < 0 || i >= (int)a->length) return; detach(); a->removeItems(i, 1); ++d->compactionCounter; if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u) compact(); }