void dictionarySet(Object *dicto, Object *keyString, Something value, Thread *thread){ EmojicodeDictionary *dict = dicto->value; size_t index = findSlot(dict, keyString); slots(dict)[index].key = keyString; slots(dict)[index].value = value; if(++dict->count > 2 * (dict->capacity/3)){ size_t oldCapacity = dict->capacity; EmojicodeDictionaryKVP *oldSlots = slots(dict); stackPush(dicto, 0, 0, thread); Object *slotso = newArray(dict->capacity * 2 * sizeof(EmojicodeDictionaryKVP)); EmojicodeDictionary *dict = stackGetThis(thread)->value; stackPop(thread); dict->slots = slotso; dict->capacity *= 2; dict->count = 0; for (size_t i = 0; i < oldCapacity; i++) { if(oldSlots[i].key){ dictionarySet(dicto, oldSlots[i].key, oldSlots[i].value, thread); } } } }
bool Tobias::isSolved( size_t max ) const { // Each student assigned to exactly one slot: for( size_t s = 0; s < getNames().size(); s++ ) { size_t count = 0; for( size_t i = 0; i < slots(); i++ ) { if( schedule.at( s * slots() + i ) ) { count++; } } if( count != 1 ) { return false; } } // Each slot at most max students: for( size_t i = 0; i < slots(); i++ ) { size_t count = 0; for( size_t s = 0; s < getNames().size(); s++ ) { if( schedule.at( s * slots() + i ) ) { count++; } } if( count > max ) { return false; } } return true; }
bool Tobias::solve( size_t max, size_t slot, size_t student ) { //std::clog << slot << "," << student << "..." << std::endl; if( student == getNames().size() ) { slot++; student = 0; } if( avaiableSlots() == 0 || slot >= slots() ) { //std::cerr << (*this) << std::endl; return isSolved( max ); } //std::clog << "!" << !slotFull( slot, max ) << std::endl; //std::clog << ">" << getChoices().at( student * slots() + slot ) << std::endl; //std::clog << "+" << !isStudentScheduled( student ) << std::endl; if( getReference().at( slot ) && !slotFull( slot, max ) && getChoices().at( student * slots() + slot ) && !isStudentScheduled( student ) ) { schedule[ student * slots() + slot ] = true; //std::clog << "Trying schedule[" << student << "," << slot << "] = true..." << std::endl; if( solve( max, slot, student + 1 ) ) { return true; } schedule[ student * slots() + slot ] = false; } // else { return solve( max, slot, student + 1 ); // } return false; }
Something dictionaryLookup(EmojicodeDictionary *dict, Object *keyString){ size_t index = findSlot(dict, keyString); if(slots(dict)[index].key){ return slots(dict)[index].value; } return NOTHINGNESS; }
void add_slot(Sink& aSink, SinkFunction aSinkFunction) { typename LockingPolicy::scope_lock sl(*this); if (slots().find(&aSink) != slots().end()) throw slot_already_added(); detail::do_bind<ParameterCount>()(aSink, aSinkFunction, slots()[&aSink]); aSink.signal_created(*this); }
void add_slot(const Key& aKey, Sink& aSink, SinkFunction aSinkFunction) { typename LockingPolicy::scope_lock sl(*this); if (slots().find(std::make_pair(aKey, &aSink)) != slots().end()) throw slot_already_added(); detail::do_bind<ParameterCount>()(aSink, aSinkFunction, slots()[std::make_pair(aKey, &aSink)]); aSink.signal_created(*this); }
static size_t findSlot(EmojicodeDictionary *dict, Object *key){ size_t index = hashString((String *)key->value) % dict->capacity; while (slots(dict)[index].key && !stringEqual(slots(dict)[index].key->value, key->value)) { index = (index + 1) % dict->capacity; } return index; }
bool Tobias::isStudentScheduled( size_t student ) const { bool scheduled = false; for( size_t i = student * slots(); i < (student + 1) * slots(); i++ ) { if( schedule.at( i ) ) { scheduled = true; break; } } return scheduled; }
virtual ~signal_with_key_base() { typename LockingPolicy::scope_lock sl(*this); for (std::size_t i = 0; i != iScope; ++i) *(iNotificationListList[i].first) = false; if (!has_slots()) return; for (typename slot_list::iterator i = slots().begin(); i != slots().end(); ++i) i->first.second->signal_destroyed(*this); }
notification_list& new_notification_scope(bool& aSignalValidFlag) const { typename LockingPolicy::scope_lock sl(*this); if (iNotificationListList.size() <= iScope) iNotificationListList.resize(iScope + 1); iNotificationListList[iScope].first = &aSignalValidFlag; iNotificationListList[iScope].second.erase(iNotificationListList[iScope].second.begin(), iNotificationListList[iScope].second.end()); for (typename slot_list::const_iterator i = slots().begin(); i != slots().end(); ++i) iNotificationListList[iScope].second.push_back(i); return iNotificationListList[iScope++].second; }
void dictionaryMark(Object *object){ EmojicodeDictionary *dict = object->value; if(dict->slots){ mark(&dict->slots); } for (size_t i = 0; i < dict->capacity; i++) { if(slots(dict)[i].key){ mark(&slots(dict)[i].key); if(isRealObject(slots(dict)[i].value)){ mark(&slots(dict)[i].value.object); } } } }
size_t Tobias::avaiableSlots() const { size_t available = 4; for( size_t i = 0; i < slots(); i++ ) { for( size_t s = 0; s < getNames().size(); s++ ) { if( schedule.at( s * slots() + i ) ) { available--; break; } } if( available == 0 ) { break; } } //std::clog << "avail: " << available << std::endl; return available; }
Slot* Record::findSlot(StringRef S) { // FIXME -- look this up in a hash table, please. for (auto &Slt : slots()) { if (Slt->slotName() == S) return Slt.get(); } return nullptr; }
void remove_slot(const Key& aKey, slot_interface& aSlot) const { typename LockingPolicy::scope_lock sl(*this); if (!has_slots()) return; for (typename notification_list_list::iterator i = iNotificationListList.begin(); i != iNotificationListList.end(); ++i) for (typename notification_list::iterator j = i->second.begin(); j != i->second.end();) if ((**j).first.first == aKey && (**j).first.second == &aSlot) j = i->second.erase(j); else ++j; for (typename slot_list::iterator i = slots().begin(); i != slots().end();) if (i->first.first == aKey && i->first.second == &aSlot) i = slots().erase(i); else ++i; }
void remove_slot(slot_interface& aSlot) const { typename LockingPolicy::scope_lock sl(*this); if (!has_slots()) return; typename slot_list::iterator existingSlot = slots().find(&aSlot); if (existingSlot != slots().end()) { for (typename notification_list_list::iterator i = iNotificationListList.begin(); i != iNotificationListList.end(); ++i) for (typename notification_list::iterator j = i->second.begin(); j != i->second.end();) if (*j == existingSlot) j = i->second.erase(j); else ++j; slots().erase(existingSlot); } }
bool Furnace::hasValidIngredient() { // Check that we have a valid input type Item* slot = &slots()[SLOT_INPUT]; if(slot->type<0){ return false; } if(createList[slot->type].output != -1){ return true; } return false; }
slotsOop slotsMap::copy_remove_one_slot(slotsOop obj, slotDesc *slot, bool mustAllocate) { assert_slots(obj, "object isn't a slotsOop"); assert(!obj->is_string(), "cannot clone strings!"); assert(slot >= slots() && slot < slotsMap::slot(length_slots()), "slotDesc not part of map"); slotsMap* new_map= (slotsMap*) remove(slot, 1, mustAllocate); if (new_map == NULL) return slotsOop(failedAllocationOop); new_map->slots_length = new_map->slots_length->decrement(); new_map->init_dependents(); mapOop new_moop = new_map->enclosing_mapOop(); new_moop->init_mark(); slotsOop new_obj; switch (slot->type->slot_type()) { case obj_slot_type: assert_smi(slot->data, "data slot contents isn't an offset"); new_obj= obj->is_byteVector() ? (slotsOop) byteVectorOop(obj)->remove(object_size(obj), smiOop(slot->data)->value(), 1, mustAllocate, true) : (slotsOop) slotsOop(obj)->remove(object_size(obj), smiOop(slot->data)->value(), 1, mustAllocate, true); if (oop(new_obj) == failedAllocationOop) return slotsOop(failedAllocationOop); // check-stores done by remove already new_map->shift_obj_slots(smiOop(slot->data), -1); new_map->object_length = new_map->object_length->decrement(); break; case arg_slot_type: { // fix up any arg slots after this one assert_smi(slot->data, "bad arg index"); fint argIndex= smiOop(slot->data)->value(); FOR_EACH_SLOTDESC(new_map, s) { if (s->is_arg_slot()) { assert_smi(s->data, "bad arg index"); fint a= smiOop(s->data)->value(); if (a > argIndex) s->data= as_smiOop(a - 1); } } } // fall through case map_slot_type: new_obj= slotsOop(obj->clone(mustAllocate)); if (oop(new_obj) == failedAllocationOop) return slotsOop(failedAllocationOop); break; default: ShouldNotReachHere(); // unexpected slot type; } new_obj->set_canonical_map(new_map); return new_obj; }
bool Tobias::slotFull( size_t slot, size_t max ) const { size_t count = 0; for( size_t i = slot; slot < schedule.size(); slot += slots() ) { if( schedule.at( i ) ) { count++; } } return (count == max); }
void Furnace::consumeFuel() { // Check that we have fuel if(slots()[SLOT_FUEL].count == 0) return; // Increment the fuel burning time based on fuel type // http://www.minecraftwiki.net/wiki/Furnace#Fuel_efficiency Item *fuelSlot = &slots()[SLOT_FUEL]; uint16_t fuelTime = 0; switch(fuelSlot->type) { case ITEM_COAL: fuelTime = 80; break; case BLOCK_PLANK: fuelTime = 15; break; case ITEM_STICK: fuelTime = 5; break; case BLOCK_WOOD: fuelTime = 15; break; case BLOCK_WORKBENCH: fuelTime = 15; break; case BLOCK_CHEST: fuelTime = 15; break; case BLOCK_BOOKSHELF: fuelTime = 15; break; case BLOCK_JUKEBOX: fuelTime = 15; break; case BLOCK_FENCE: fuelTime = 15; break; case BLOCK_WOODEN_STAIRS: fuelTime = 15; break; case ITEM_LAVA_BUCKET: fuelTime = 1000; break; default: break; } if(fuelTime > 0) { data->burnTime += fuelTime; // Now decrement the fuel & reset fuelSlot->count--; if (fuelSlot->count == 0) { *fuelSlot = Item(); } } // Update our block type if need be updateBlock(); }
void Furnace::smelt() { // Check if we're cooking if (isCooking()) { // Convert where applicable Item* inputSlot = &slots()[SLOT_INPUT]; Item* fuelSlot = &slots()[SLOT_FUEL]; Item* outputSlot = &slots()[SLOT_OUTPUT]; int32_t creationID = createList[inputSlot->getType()].output; // Update other params if we actually converted if (creationID != -1 && outputSlot->getCount() != 64) { // Check if the outputSlot is empty if (outputSlot->getType() == -1) { outputSlot->setType(creationID); outputSlot->setCount(1); outputSlot->setHealth(createList[inputSlot->getType()].meta); inputSlot->setCount(inputSlot->getCount() - 1); m_data->cookTime = 0; } // Ok - now check if the current output slot contains the same stuff if (outputSlot->getType() == creationID && m_data->cookTime != 0) { // Increment output and decrememnt the input source outputSlot->setCount(outputSlot->getCount() + createList[inputSlot->getType()].count); inputSlot->setCount(inputSlot->getCount() - 1); outputSlot->setHealth(createList[inputSlot->getType()].meta); m_data->cookTime = 0; if (inputSlot->getCount() == 0) { *inputSlot = Item(); } } } } }
void SnapshotExtractor::ExtractSlotArrayIfNeeded(Js::ScriptContext* ctx, Js::Var* scope) { if(this->m_marks.IsMarked(scope)) { NSSnapValues::SlotArrayInfo* slotInfo = this->m_pendingSnap->GetNextAvailableSlotArrayEntry(); Js::ScopeSlots slots(scope); slotInfo->SlotId = TTD_CONVERT_VAR_TO_PTR_ID(scope); slotInfo->ScriptContextLogId = ctx->ScriptContextLogTag; slotInfo->SlotCount = slots.GetCount(); slotInfo->Slots = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<TTDVar>(slotInfo->SlotCount); for(uint32 j = 0; j < slotInfo->SlotCount; ++j) { slotInfo->Slots[j] = slots.Get(j); } if(slots.IsFunctionScopeSlotArray()) { Js::FunctionBody* fb = slots.GetFunctionBody(); slotInfo->isFunctionBodyMetaData = true; slotInfo->OptFunctionBodyId = TTD_CONVERT_FUNCTIONBODY_TO_PTR_ID(fb); #if ENABLE_TTD_INTERNAL_DIAGNOSTICS Js::PropertyId* propertyIds = fb->GetPropertyIdsForScopeSlotArray(); slotInfo->DebugPIDArray = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<Js::PropertyId>(slotInfo->SlotCount); for(uint32 j = 0; j < slotInfo->SlotCount; ++j) { slotInfo->DebugPIDArray[j] = propertyIds[j]; } #endif } else { slotInfo->isFunctionBodyMetaData = false; slotInfo->OptFunctionBodyId = TTD_INVALID_PTR_ID; #if ENABLE_TTD_INTERNAL_DIAGNOSTICS slotInfo->DebugPIDArray = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<Js::PropertyId>(slotInfo->SlotCount); for(uint32 j = 0; j < slotInfo->SlotCount; ++j) { slotInfo->DebugPIDArray[j] = (Js::PropertyId)0; } #endif } this->m_marks.ClearMark(scope); } }
//accessors void cInvintory::Deconstruct(char *&buffer) const{ uint8_t mask(0x80), *slots(reinterpret_cast<uint8_t*>(buffer)); buffer++;// skip this *slots=0;// zero it out for(uint8_t i(0); i < NUMOFINVINTORYSLOTS; i++){ if(Invintory[i]){ *slots|=mask;// mark the item Invintory[i]->Deconstruct(buffer); } mask>>=1; } }
void main() { int total=100; char choice; clrscr(); cout << "Crappy program gambling game"; gotoxy(12,12); cout << "Press any key to get on da street"; getch(); while(choice!='Q') { clrscr(); cout << "Dollars : " << total << endl; cout << "(C)raps" << endl << "(B)lackjack" << endl << "(R)oulette" << endl << "(S)lots" << endl << "(Q)uit"; choice=getch(); choice=toupper(choice); switch(choice) { case('C'): { clrscr(); total=craps(total); break; } case('B'): { clrscr(); total=blackjack(total); break; } case('Q'): { clrscr(); quit(total); getch(); break; } case('R'): { clrscr(); total=roulette(total); break; } case('S'): { total=slots(total); break; } } } }
void Furnace::smelt() { // Check if we're cooking if(isCooking()) { // Convert where applicable Item* inputSlot = &slots()[SLOT_INPUT]; Item* fuelSlot = &slots()[SLOT_FUEL]; Item* outputSlot = &slots()[SLOT_OUTPUT]; int32_t creationID = createList[inputSlot->type].output; // Update other params if we actually converted if(creationID != -1 && outputSlot->count != 64) { // Check if the outputSlot is empty if(outputSlot->type == -1) { outputSlot->type = creationID; outputSlot->count = 0; } // Ok - now check if the current output slot contains the same stuff if(outputSlot->type == creationID) { // Increment output and decrememnt the input source outputSlot->count+=createList[inputSlot->type].count; inputSlot->count--; outputSlot->health = createList[inputSlot->type].meta; data->cookTime = 0; if(inputSlot->count == 0) { *inputSlot = Item(); } } } } }
void TestConstrainedNormal(REAL begin, REAL end, REAL mean, REAL stdev){ unsigned int numbers = 1000; unsigned int steps = 10; TPZVec<int> slots(steps,0); REAL increment = (end-begin)/steps; TPZConstrainedNormalRandom<REAL> r(begin, end, mean, stdev); for (unsigned int i = 0; i < numbers; ++i) { REAL value = r.next(); BOOST_ASSERT(value > begin); BOOST_ASSERT(value < end); slots[std::floor((value-begin)/increment)]++; } //PrintDistribution(begin, steps, slots, increment); }
void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform) { // Limitations: sorting is quite simple, and handles many // cases wrong, partially due to polygons being sorted per // bucket. // // a) mixed triangles/quads are sorted wrong // b) mixed materials are sorted wrong // c) more than 65k faces are sorted wrong // d) intersecting objects are sorted wrong // e) intersecting polygons are sorted wrong // // a) can be solved by making all faces either triangles or quads // if they need to be z-sorted. c) could be solved by allowing // larger buckets, b) and d) cannot be solved easily if we want // to avoid excessive state changes while drawing. e) would // require splitting polygons. RAS_MeshSlot::iterator it; size_t j; for (ms.begin(it); !ms.end(it); ms.next(it)) { unsigned int nvert = (int)it.array->m_type; unsigned int totpoly = it.totindex/nvert; if (totpoly <= 1) continue; if (it.array->m_type == RAS_DisplayArray::LINE) continue; // Extract camera Z plane... const MT_Vector3 pnorm(transform.getBasis()[2]); // unneeded: const MT_Scalar pval = transform.getOrigin()[2]; vector<polygonSlot> slots(totpoly); /* get indices and z into temporary array */ for (j=0; j<totpoly; j++) slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm); /* sort (stable_sort might be better, if flickering happens?) */ std::sort(slots.begin(), slots.end(), backtofront()); /* get indices from temporary array again */ for (j=0; j<totpoly; j++) slots[j].set(it.index, j*nvert, nvert); } }
void TestNormal(REAL mean, REAL stdev){ unsigned int numbers = 1000; unsigned int steps = 20; TPZVec<int> slots(steps,0); REAL begin = mean - 5; REAL end = mean + 5; REAL increment = (end-begin)/steps; TPZNormalRandom<REAL> r(mean, stdev); for (unsigned int i = 0; i < numbers; ++i) { REAL value; do { value = r.next(); } while (value <= begin || value >= end); slots[std::floor((value-begin)/increment)]++; } //PrintDistribution(begin, steps, slots, increment); }
void TestUniform(REAL begin, REAL end){ unsigned int numbers = 1000; unsigned int steps = 10; TPZVec<int> slots(steps,0); REAL increment = (end-begin)/steps; TPZUniformRandom<REAL> r(begin, end); for (unsigned int i = 0; i < numbers; ++i) { REAL value = r.next(); BOOST_ASSERT(value > begin); BOOST_ASSERT(value < end); slots[std::floor((value-begin)/increment)]++; } // for (unsigned int i = 0; i < steps; ++i) { // BOOST_ASSERT(slots[i] > .8*numbers/steps); // BOOST_ASSERT(slots[i] < 1.2*numbers/steps); // } }
TEST(ActivityTest, TestAdoptFailure) { MockActivityService mockActivityService; MockBusClient serviceClient; MojInt32 activityId = 1; ActivityPtr activity = Activity::PrepareAdoptedActivity(activityId); MojRefCountedPtr<MockActivitySlots> slots(new MockActivitySlots(activity)); activity->Adopt(serviceClient); MockRequestPtr req = serviceClient.GetLastRequest(); // Should handle the error and pass it along to the error slot slots->ExpectError(); MojObject response; req->ReplyNow(response, MojErrInternal); slots->Check(); }
TEST(ActivityTest, TestActivityManagerOffline) { MockActivityService mockActivityService; MockBusClient serviceClient; mockActivityService.SetOffline(true); MojInt32 activityId = 1; ActivityPtr activity = Activity::PrepareAdoptedActivity(activityId); MojRefCountedPtr<MockActivitySlots> slots(new MockActivitySlots(activity)); activity->Adopt(serviceClient); MockRequestPtr req = serviceClient.GetLastRequest(); // Should handle the error and pass it along to the error slot slots->ExpectError(); mockActivityService.HandleRequest(req); slots->Check(); }