Example #1
0
int main(int argc, char *argv[])
{
    FILE *fp;
    char buffer[BUFSIZ];
    SET *odd;
    int words;


    /* Check usage and open the file. */

    if (argc != 2) {
        fprintf(stderr, "usage: %s file1\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if ((fp = fopen(argv[1], "r")) == NULL) {
        fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
        exit(EXIT_FAILURE);
    }


    /* Insert or delete words to compute their parity. */

words = 0;
    odd = createSet(MAX_SIZE);

    while (fscanf(fp, "%s", buffer) == 1) {
        words ++;

        if (hasElement(odd, buffer))
            removeElement(odd, buffer);
        else
            addElement(odd, buffer);
    }

    printf("%d total words\n", words);
    printf("%d words occur an odd number of times\n", numElements(odd));
    fclose(fp);

    destroySet(odd);
    exit(EXIT_SUCCESS);
}
Example #2
0
/* remove a label */
int removeLabel(t_translation_infos *infos, char *ID)
{
   t_asm_label *result;
   int asm_errorcode;
   
   /* initialize the value of `asm_errorcode' */
   asm_errorcode = ASM_OK;
   
   /* initialize the value of `result' */
   result = findLabel(infos, ID, &asm_errorcode);
   
   /* postconditions */
   if (result == NULL)
      return asm_errorcode;
   
   /* remove the label from the list */
   infos->labels = removeElement(infos->labels, result);
   
   return asm_errorcode;
}
Example #3
0
void removeSubKey(const char *key)
{
	
	int i;
	for(i = 0; i < TableSize; i++)
	{
		HashTableVoidEntry *current = _buckets[i];
		
		while(current != NULL)
		{	
			if(strstr(current->_key, key))
			{
				if(strcmp(current->_key, key))
					removeElement(strstr(current->_key,key));
				//printf("Found %s\n", strstr(current->_key,key));	
			}
			current = current->_next;
		}
	}
}
Example #4
0
void Level::replaceSquare(Vec2 pos, PSquare square) {
  if (contains(tickingSquares, getSquare(pos)))
    removeElement(tickingSquares, getSquare(pos));
  Creature* c = squares[pos]->getCreature();
  for (Item* it : squares[pos]->getItems())
    square->dropItem(squares[pos]->removeItem(it));
  squares[pos]->onConstructNewSquare(square.get());
  addLightSource(pos, squares[pos]->getLightEmission(), -1);
  square->setCovered(squares[pos]->isCovered());
  square->addLight(squares[pos]->getTotalLight());
  square->setBackground(squares[pos].get());
  squares[pos] = std::move(square);
  squares[pos]->setPosition(pos);
  squares[pos]->setLevel(this);
  if (c) {
    squares[pos]->putCreatureSilently(c);
  }
  addLightSource(pos, squares[pos]->getLightEmission(), 1);
  updateVisibility(pos);
}
Example #5
0
void daeSTLDatabase::validate()
{
	for( unsigned int i = 0; i < documents.size(); i++ ) {
		if (documents[i]->getModified() ) {
			daeDocument *tmp = documents[i];
			const daeElementRefArray &rea = tmp->getRemovedArray();
			unsigned int x;
			for ( x = 0; x < rea.getCount(); x++ ) {
				removeElement( tmp, rea[x] );
			}

			const daeElementRefArray &iea = tmp->getInsertedArray();
			for ( x = 0; x < iea.getCount(); x++ ) {
				insertElement( tmp, iea[x] );
			}
			
			tmp->setModified(false);
		}
	}
}
Example #6
0
CostInfo TaskMap<CostInfo>::removeTask(Task* task) {
  CostInfo cost;
  if (completionCost.count(task)) {
    cost = completionCost.at(task);
    completionCost.erase(task);
  }
  if (auto pos = getPosition(task))
    marked[*pos] = nullptr;
  for (int i : All(tasks))
    if (tasks[i].get() == task) {
      removeIndex(tasks, i);
      break;
    }
  if (creatureMap.contains(task))
    creatureMap.erase(task);
  if (positionMap.count(task)) {
    removeElement(reversePositions[positionMap.at(task)], task);
    positionMap.erase(task);
  }
  return cost;
}
Example #7
0
void deleteNode(struct Graph* graph, int n)
{
	int i;
	
	if (graph->array[n].head == NULL && graph->array[n].army == ' ' && graph->array[n].Ci == 0){
		DEBUG_PRINTF("Error : node %d has already been deleted !\n\n", n);
		return;
	}
	else
	{
		graph->array[n].head = NULL;
		graph->array[n].army = ' ';
		graph->array[n].Ci = 0;
	}
	
	// Deletes element in the linked lists
	for (i=0;i<graph->N;++i)
    {
		removeElement(graph, n, i);
	}
}
Example #8
0
daeElement *
daeMetaElementArrayAttribute::placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after )
{
	if ((parent == NULL)||(child == NULL))
		return NULL;
	if ( child->getMeta() != _elementType || ( child->getElementName() != NULL && strcmp( child->getElementName(), _name ) != 0 )  ) {
		return NULL;
	}
	if (child->getParentElement() == parent) {
		//I Don't know why this gets called when the child already has this as parent.
		return child;
	}
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
	if ( _maxOccurs != -1 && (daeInt)era->getCount()-offset >= _maxOccurs ) {
		return NULL;
	}
	removeElement( child->getParentElement(), child );
	child->setParentElement( parent );

	if ( before != NULL || after != NULL ) {
		if ( before != NULL && before->getMeta() == _elementType ) {
			size_t idx(0);
			if ( era->find( before, idx ) == DAE_OK ) {
				era->insertAt( idx, child );
			}
		}
		else if ( after != NULL && after->getMeta() == _elementType ) {
			size_t idx(0);
			if ( era->find( after, idx ) == DAE_OK ) {
				era->insertAt( idx+1, child );
			}
		}
	}
	else {
		era->append(child);
	}
	ordinal = _ordinalOffset;

	return child;
}
Example #9
0
void VEffect::_updateElements(const Real &dt)
{
	VElementIterator itr = mElements.begin();
	while (itr != mElements.end())
	{
		VEffectElement *element = *itr;

		if (element != VNULL && element->isActive())
		{
			if (element->isDestroy())
			{
				removeElement(element);
			}
			else
			{
				element->update(dt, mTransform);
			}
		}

		++itr;
	}
}
Example #10
0
int performLivenessOnBlock(t_basic_block *bblock, t_list *out)
{
   t_list *current_element;
   t_list *cloned_list;
   t_cflow_Node *next_node;
   t_cflow_Node *current_node;
   int modified;

   /* initialize the local variables */
   modified = 0;

   if (bblock == NULL || bblock->nodes == NULL) {
      cflow_errorcode = CFLOW_INVALID_BBLOCK;
      return modified;
   }

   current_element = getLastElement(bblock->nodes);
   current_node = (t_cflow_Node *) LDATA(current_element);
   assert(current_node != NULL);

   /* update the out set */
   current_node->out = addListToSet
         (current_node->out, out, NULL, &modified);

   /* update the in list */
   cloned_list = cloneList(current_node->out);
   
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#else
   if ((current_node->uses)[0] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   
   if ((current_node->uses)[2] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#endif



#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
   if (current_node->def != NULL)
#endif
   {
      int found = 0;
      int current_use_idx = 0;
      
      do
      {
         if ((current_node->uses)[current_use_idx] != NULL)
         {
            if ((current_node->uses)[current_use_idx]->ID == current_node->def->ID)
               found = 1;
         }
         
         current_use_idx++;
         
      } while((found == 0) && (current_use_idx < 3));
      
      if (!found)
         cloned_list = removeElement(cloned_list, current_node->def);
   }
   
   current_node->in = addListToSet
         (current_node->in, cloned_list, NULL, &modified);

   /* remove the cloned list */
   freeList(cloned_list);
   
   /* set the new value of next_node */
   next_node = current_node;
   current_element = LPREV(current_element);
   while (current_element != NULL)
   {
      /* take a new node */
      current_node = (t_cflow_Node *) LDATA(current_element);
      assert(current_node != NULL);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(next_node->in);
      
      /* update the out list */
      current_node->out = addListToSet
            (current_node->out, cloned_list, NULL, &modified);
      
      /* remove the cloned list */
      freeList(cloned_list);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(current_node->out);
      
      /* update the in list */
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#else
      if ((current_node->uses)[0] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#endif
      
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
      if (current_node->def != NULL)
#endif
      {
         int found = 0;
         int current_use_idx = 0;
      
         do
         {
            if ((current_node->uses)[current_use_idx] != NULL)
            {
               if ((current_node->uses)[current_use_idx]->ID
                        == current_node->def->ID)
               {
                  found = 1;
               }
            }
            current_use_idx++;
         
         } while((found == 0) && (current_use_idx < 3));
      
         if (!found)
            cloned_list = removeElement(cloned_list, current_node->def);
      }

      current_node->in = addListToSet
            (current_node->in, cloned_list, NULL, &modified);

      /* remove the cloned list */
      freeList(cloned_list);
      
      /* update the loop control informations */
      current_element = LPREV(current_element);
      next_node = current_node;
   }

   /* return the `modified' value */
   return modified;
}
Example #11
0
int main(void)
{
	int i; char buffer[32];

	ArrayList *L1 = createArrayList(-1);
	ArrayList *L2 = createArrayList(-1);

	FILE *ifp = fopen("names.txt", "rb");

	// Read all names from the file and add them to L1.
	while (fscanf(ifp, "%s", buffer) != EOF)
		put(L1, buffer);

	// Add the names to L2 in reverse order.
	for (i = getSize(L1) - 1; i >= 0; i--)
		put(L2, get(L1, i));

	// Print the contents of L1.
	printf("\n-- LIST 1: --\n");
	printArrayList(L1);

	// Print the contents of L2.
	printf("\n-- LIST 2 (First Names): --\n");
	printArrayList(L2);

	// Swap last names with first names in L2.
	for (i = 0; i < getSize(L2); i++)
	{
		if (strcmp(get(L2, i), "Sean") == 0)
			set(L2, i, "Szumlanski");
		else if (strcmp(get(L2, i), "Adam") == 0)
			set(L2, i, "Bouters");
		else if (strcmp(get(L2, i), "Antoniya") == 0)
			set(L2, i, "Petkova");
		else if (strcmp(get(L2, i), "Ashkan") == 0)
			set(L2, i, "Paya");
		else if (strcmp(get(L2, i), "Grant") == 0)
			set(L2, i, "Van Horn");
	}

	// Print the contents of L2.
	printf("\n-- LIST 2 (Last Names): --\n");
	printArrayList(L2);

	// Print L1 (in reverse order) and L2, to match up first and last names.
	printf("\n-- COMBINED LISTS (First and Last Names): --\n");
	for (i = 0; i < getSize(L2); i++)
		printf("%s %s\n", get(L1, getSize(L1) - 1 - i), get(L2, i));

	// Add elements from L1 to the end of L1 (in reverse order).
	printf("\n");
	for (i = getSize(L1) - 1; i >= 0; i--)
		printf("Adding %s to L1 ...\n", put(L1, get(L1, i)));

	// Print the contents of L1.
	printf("\n-- LIST 1: --\n");
	printArrayList(L1);

	// Insert a string at the beginning of list L1.
	insertElement(L1, 0, "List of Names:");

	// Print the contents of L1.
	printf("\n-- LIST 1: --\n");
	printArrayList(L1);

	// Remove all elements from L1.
	while (getSize(L1))
		removeElement(L1, 0);

	// Print L1, which is now an empty list.
	printf("\n-- LIST 1: --\n");
	printArrayList(L1);

	// Destroy our lists.
	L1 = destroyArrayList(L1);
	L2 = destroyArrayList(L2);

	// Make sure L1 is good and destroyed (and that destroyArrayList doesn't
	// segfault when passed a NULL pointer).
	L1 = destroyArrayList(L1);

	// Print the empty lists one last time.
	printf("\n-- LIST 1: --\n");
	printArrayList(L1);

	printf("\n-- LIST 2: --\n");
	printArrayList(L2);

	return 0;
}
Example #12
0
void Tribe::removeMember(const Creature* c) {
  if (c == leader)
    leader = nullptr;
  removeElement(members, c);
}
Example #13
0
void Level::eraseCreature(Creature* c) {
  removeElement(creatures, c);
  if (c->isPlayer())
    player = nullptr;
}
Example #14
0
void Equipment::unequip(const Item* item) {
  EquipmentSlot slot = item->getEquipmentSlot();
  CHECK(items.count(slot));
  removeElement(items.at(slot), item);
}
Example #15
0
// Creates a new DracView to summarise the current state of the game
DracView newDracView(char *pastPlays, PlayerMessage messages[]) {
	DracView dracView = malloc(sizeof(struct dracView));
	dracView->g = newGameView(pastPlays, messages);
	dracView->vampLocation = NOWHERE;
	dracView->traps = newTrail(TRAIL_SIZE);

	// If pastPlays is empty, we just return early.
	if (strcmp(pastPlays, "") == 0) {
		return dracView;
	}

	char *currentPlayMarker = pastPlays;
	char currentPlay[8] = {'\0'};
	char givenLocation[3] = {'\0'};
	LocationID currentPlace = NOWHERE;
	while (currentPlayMarker != NULL) {
		memcpy(currentPlay, currentPlayMarker, 8);

		// We isolate the location part for easy access..
		memcpy(givenLocation, currentPlay + 1, 2);

		currentPlace = abbrevToID(givenLocation);

		if (currentPlay[0] == 'D') {
			// Then we parse each of the next four characters.
			for (int i = 3; i < 6; i++) {
				if (i == 3 || i == 4) {
					switch (currentPlay[i]) {
						// TRAP PLACED
						case 'T':
							prepend(dracView->traps, currentPlace);
							break;
							// VAMPIRE PLACED
						case 'V':
							dracView->vampLocation = currentPlace;
							break;
							// NOTHING
						default:
							break;
					}
				} else if (i == 5) {
					switch (currentPlay[i]) {
						// TRAP LEAVES
						case 'M':
							while (showElement(dracView->traps, TRAIL_SIZE - 1) != NOWHERE) {
								prepend(dracView->traps, NOWHERE);
							}
							prepend(dracView->traps, NOWHERE);
							break;
							// VAMPIRE MATURES
						case 'V':
							dracView->vampLocation = NOWHERE;
							break;
							// NOTHING
						default:
							break;
					}
				}
			}
		} else {
			// Then we parse each of the next four characters.
			for (int i = 3; i < 7; i++) {
				switch (currentPlay[i]) {
					// TRAP FOUND
					case 'T':
						removeElement(dracView->traps, abbrevToID(givenLocation));
						break;
						// VAMPIRE FOUND
					case 'V':
						dracView->vampLocation = NOWHERE;
						break;
						// NOTHING
					default:
						break;
				}
			}
		}

		if (currentPlay[7] == '\0') break;
		currentPlayMarker += 8;
	}
	return dracView;
}
Example #16
0
void Level::eraseCreature(Creature* c, Vec2 coord) {
  removeElement(creatures, c);
  if (c->isPlayer())
    player = nullptr;
  unplaceCreature(c, coord);
}
void ItemLibrarySortedModel<T>::clearElements()
{
    while (m_elementOrder.count() > 0)
        removeElement(m_elementOrder.at(0).libId);
}
Example #18
0
void RAM::initPins()
{
	int oldWordSize = m_dataIn.size();
	int oldAddressSize = m_address.size();
	
	int newWordSize = dataInt("wordSize");
	int newAddressSize = dataInt("addressSize");
	
	if ( newAddressSize == oldAddressSize &&
			newWordSize == oldWordSize )
		return;
	
	QStringList leftPins; // Pins on left of IC
	leftPins << "CS" << "OE" << "WE";
	for ( int i = 0; i < newAddressSize; ++i )
		leftPins << QString("A%1").arg( QString::number(i) );
	
	QStringList rightPins; // Pins on right of IC
	for ( unsigned i = newWordSize; i > 0; --i )
		rightPins << QString("DI%1").arg( QString::number(i-1) );
	for ( unsigned i = newWordSize; i > 0; --i )
		rightPins << QString("DO%1").arg( QString::number(i-1) );
	
	// Make pin lists of consistent sizes
	for ( unsigned i = leftPins.size(); i < rightPins.size(); ++i )
		leftPins.append("");
	for ( unsigned i = rightPins.size(); i < leftPins.size(); ++i )
		rightPins.prepend("");
	
	QStringList pins = leftPins + rightPins;
	
	initDIPSymbol( pins, 72 );
	initDIP(pins);
	
	ECNode *node;
	
	if (!m_pCS)
	{
		node =  ecNodeWithID("CS");
		m_pCS = createLogicIn(node);
		m_pCS->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if (!m_pOE)
	{
		node =  ecNodeWithID("OE");
		m_pOE = createLogicIn(node);
		m_pOE->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if (!m_pWE)
	{
		node =  ecNodeWithID("WE");
		m_pWE = createLogicIn(node);
		m_pWE->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if ( newWordSize > oldWordSize )
	{
		m_dataIn.resize(newWordSize);
		m_dataOut.resize(newWordSize);
		
		for ( int i = oldWordSize; i < newWordSize; ++i )
		{
			node = ecNodeWithID( QString("DI%1").arg( QString::number(i) ) );
			m_dataIn.insert( i, createLogicIn(node) );
			m_dataIn[i]->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) ); 
			
			node = ecNodeWithID( QString("DO%1").arg( QString::number(i) ) );
			m_dataOut.insert( i, createLogicOut(node, false) );
		}
	}
	else if ( newWordSize < oldWordSize )
	{
		for ( int i = newWordSize; i < oldWordSize; ++i )
		{
			QString id = QString("DO%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_dataIn[i], false );
			removeNode(id);
			
			id = QString("DI%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_dataOut[i], false );
			removeNode(id);
		}
		
		m_dataIn.resize(newWordSize);
		m_dataOut.resize(newWordSize);
	}
	
	if ( newAddressSize > oldAddressSize )
	{
		m_address.resize(newAddressSize);
		
		for ( int i = oldAddressSize; i < newAddressSize; ++i )
		{
			node = ecNodeWithID( QString("A%1").arg( QString::number(i) ) );
			m_address.insert( i, createLogicIn(node) );
			m_address[i]->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
		}
	}
	else if ( newAddressSize < oldAddressSize )
	{
		for ( int i = newAddressSize; i < oldAddressSize; ++i )
		{
			QString id = QString("A%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_address[i], false );
			removeNode(id);
		}
		
		m_address.resize(newAddressSize);
	}
}
Example #19
0
void List::remove(double number)
{
	Double* doubleObject = new Double(number);
	removeElement(doubleObject);
}
Example #20
0
void Territory::remove(Position pos) {
  removeElement(allSquaresVec, pos);
  allSquares.erase(pos);
  clearCache();
}
Example #21
0
int main(void)
{
	int	num[] = { 4, 5 };
	int	a = removeElement(num, 2, 4);
	return(0);
}
Example #22
0
void removeElements(std::vector<T>& vec, const std::vector<T>& elements) {
	for (const auto& element : elements) {
		removeElement(vec, element);
	}
}
Example #23
0
void Level::changeLevel(StairDirection dir, StairKey key, Creature* c) {
  removeElement(creatures, c);
  getSafeSquare(c->getPosition())->removeCreature();
  bucketMap->removeElement(c->getPosition(), c);
}
v8::Handle<v8::Value> V8HTMLSelectElement::removeMethodCustom(const v8::Arguments& args)
{
    HTMLSelectElement* imp = V8HTMLSelectElement::toNative(args.Holder());
    return removeElement(imp, args);
}
Example #25
0
void Level::changeLevel(Level* destination, Vec2 landing, Creature* c) {
  removeElement(creatures, c);
  getSafeSquare(c->getPosition())->removeCreature();
  bucketMap->removeElement(c->getPosition(), c);
  model->changeLevel(destination, landing, c);
}
void V8HTMLOptionsCollection::removeMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(args.Holder());
    HTMLSelectElement* base = toHTMLSelectElement(imp->ownerNode());
    removeElement(base, args);
}
Example #27
0
void List::remove(int number)
{
	Int* intObject = new Int(number);
	removeElement(intObject);
}
Example #28
0
void EventGenerator<Listener>::removeListener(Listener* l) {
  removeElement(listeners, l);
}
v8::Handle<v8::Value> V8HTMLSelectElement::removeCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.HTMLSelectElement.remove");
    HTMLSelectElement* imp = V8HTMLSelectElement::toNative(args.Holder());
    return removeElement(imp, args);
}
void CmdProjectLibraryAddElement<ElementType>::performUndo() {
  removeElement();  // can throw
}