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);
            }
        }
    }
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 5
0
		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);
		}
Ejemplo n.º 6
0
		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;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
		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);
	}
Ejemplo n.º 10
0
		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;
		}
Ejemplo n.º 11
0
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);
            }
        }
    }
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
Archivo: TIL.cpp Proyecto: google/ohmu
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;
}
Ejemplo n.º 14
0
		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;
		}
Ejemplo n.º 15
0
		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);
			}
		}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
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);
}
Ejemplo n.º 19
0
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();
}
Ejemplo n.º 20
0
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();
        }
      }
    }
  }
}
Ejemplo n.º 21
0
    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);
        }
    }
Ejemplo n.º 22
0
//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;
	}
}
Ejemplo n.º 23
0
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;
			}
		}
	}
}
Ejemplo n.º 24
0
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();
        }
      }
    }
  }
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
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);
	}
}
Ejemplo n.º 27
0
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);
}
Ejemplo n.º 28
0
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);
//    }
}
Ejemplo n.º 29
0
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();
}
Ejemplo n.º 30
0
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();
}