Пример #1
0
void Test2()//PushFront   PopFront   Find
{ 
	PSListNode ret = NULL;
	PSListNode pHead = NULL;
	InitList(&pHead);
	PushFront(&pHead,0);
	PushFront(&pHead,1);
	PushFront(&pHead,2);
	PushFront(&pHead,3);
	PushFront(&pHead,4);

	PrintList(&pHead);

	PopFront(&pHead);
	PopFront(&pHead);
	//PopFront(&pHead);
	//PopFront(&pHead);
	//PopFront(&pHead);
	//PopFront(&pHead);

	PrintList(&pHead);

	ret = Find(&pHead,2);
	if (ret == NULL)
	{
		printf("no find\n");
	} 
	else
	{
		printf("%d \n",ret->data);
	}
}
std::tuple<unsigned short, unsigned short, unsigned short> LongestCommonSubwordCyclic(CWord u, CWord v) {
  unsigned short max_common_prefix = 0;
  unsigned short u_max_begin = u.size();
  unsigned short v_max_begin = v.size();

  for (unsigned short current_u_begin = 0; current_u_begin < u.size(); ++current_u_begin) {
    for (unsigned short current_v_begin = 0; current_v_begin < v.size(); ++current_v_begin) {
      auto u_copy = u;
      auto v_copy = v;
      unsigned short current_common_prefix_length = 0;
      while (u_copy.GetFront() == v_copy.GetFront()) {
        ++current_common_prefix_length;
        u_copy.PopFront();
        if (u_copy.Empty()) {
          break;
        }
        v_copy.PopFront();
        if (v_copy.Empty()) {
          break;
        }
      }
      if (current_common_prefix_length > max_common_prefix) {
        u_max_begin = current_u_begin;
        v_max_begin = current_v_begin;
        max_common_prefix = current_common_prefix_length;
      }
      v.CyclicLeftShift();
    }
    u.CyclicLeftShift();
  }

  return std::make_tuple(u_max_begin, v_max_begin, max_common_prefix);
}
Пример #3
0
void
BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot,
                   std::deque<LayerPolygon>& aLayers)
{
  if (aLayers.empty()) {
    return;
  }

  const gfx::Polygon& plane = aRoot->First();
  std::deque<LayerPolygon> backLayers, frontLayers;

  for (LayerPolygon& layerPolygon : aLayers) {
    const Maybe<gfx::Polygon>& geometry = layerPolygon.geometry;

    size_t pos = 0, neg = 0;
    nsTArray<float> dots = geometry->CalculateDotProducts(plane, pos, neg);

    // Back polygon
    if (pos == 0 && neg > 0) {
      backLayers.push_back(Move(layerPolygon));
    }
    // Front polygon
    else if (pos > 0 && neg == 0) {
      frontLayers.push_back(Move(layerPolygon));
    }
    // Coplanar polygon
    else if (pos == 0 && neg == 0) {
      aRoot->layers.push_back(Move(layerPolygon));
    }
    // Polygon intersects with the splitting plane.
    else if (pos > 0 && neg > 0) {
      nsTArray<gfx::Point4D> backPoints, frontPoints;
      geometry->SplitPolygon(plane.GetNormal(), dots, backPoints, frontPoints);

      const gfx::Point4D& normal = geometry->GetNormal();
      Layer *layer = layerPolygon.layer;

      if (backPoints.Length() >= 3) {
        backLayers.push_back(LayerPolygon(layer, Move(backPoints), normal));
      }

      if (frontPoints.Length() >= 3) {
        frontLayers.push_back(LayerPolygon(layer, Move(frontPoints), normal));
      }
    }
  }

  if (!backLayers.empty()) {
    aRoot->back.reset(new BSPTreeNode(PopFront(backLayers)));
    BuildTree(aRoot->back, backLayers);
  }

  if (!frontLayers.empty()) {
    aRoot->front.reset(new BSPTreeNode(PopFront(frontLayers)));
    BuildTree(aRoot->front, frontLayers);
  }
}
Пример #4
0
void
BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot,
                   std::deque<gfx::Polygon3D>& aPolygons)
{
  if (aPolygons.empty()) {
    return;
  }

  const gfx::Polygon3D& splittingPlane = aRoot->First();
  std::deque<gfx::Polygon3D> backPolygons, frontPolygons;

  for (gfx::Polygon3D& polygon : aPolygons) {
    size_t pos = 0, neg = 0;
    nsTArray<float> dots = CalculateDotProduct(splittingPlane, polygon,
                                               pos, neg);

    // Back polygon
    if (pos == 0 && neg > 0) {
      backPolygons.push_back(std::move(polygon));
    }
    // Front polygon
    else if (pos > 0 && neg == 0) {
     frontPolygons.push_back(std::move(polygon));
    }
    // Coplanar polygon
    else if (pos == 0 && neg == 0) {
      aRoot->polygons.push_back(std::move(polygon));
    }
    // Polygon intersects with the splitting plane.
    else if (pos > 0 && neg > 0) {
      nsTArray<gfx::Point3D> backPoints, frontPoints;
      SplitPolygon(splittingPlane, polygon, dots, backPoints, frontPoints);

      backPolygons.push_back(gfx::Polygon3D(std::move(backPoints)));
      frontPolygons.push_back(gfx::Polygon3D(std::move(frontPoints)));
    }
  }

  if (!backPolygons.empty()) {
    aRoot->back.reset(new BSPTreeNode(PopFront(backPolygons)));
    BuildTree(aRoot->back, backPolygons);
  }

  if (!frontPolygons.empty()) {
    aRoot->front.reset(new BSPTreeNode(PopFront(frontPolygons)));
    BuildTree(aRoot->front, frontPolygons);
  }
}
Пример #5
0
 Request* Dequeue()
 {
     Request* const theReqPtr = PopFront(kIoQueueIdx);
     if (! theReqPtr) {
         return 0;
     }
     // If there are more than one "sub request" then the list head has
     // buffer count larger than request max buffers per request.
     int theBufCount = theReqPtr->mBufferCount;
     while ((theBufCount -= mRequestBufferCount) > 0) {
         Request* const thePtr = PopFront(kIoQueueIdx);
         QCASSERT(thePtr);
         Insert(*theReqPtr, *thePtr);
     }
     return theReqPtr;
 }
Пример #6
0
uint32_t ResourceQueue::EvictBefore(uint64_t aOffset, ErrorResult& aRv)
{
  SBR_DEBUG("EvictBefore(%llu)", aOffset);
  uint32_t evicted = 0;
  while (ResourceItem* item = ResourceAt(0)) {
    SBR_DEBUG("item=%p length=%d offset=%llu",
              item, item->mData->Length(), mOffset);
    if (item->mData->Length() + mOffset >= aOffset) {
      if (aOffset <= mOffset) {
        break;
      }
      uint32_t offset = aOffset - mOffset;
      mOffset += offset;
      evicted += offset;
      RefPtr<MediaByteBuffer> data = new MediaByteBuffer;
      if (!data->AppendElements(item->mData->Elements() + offset,
                                item->mData->Length() - offset,
                                fallible)) {
        aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
        return 0;
      }

      item->mData = data;
      break;
    }
    mOffset += item->mData->Length();
    evicted += item->mData->Length();
    delete PopFront();
  }
  return evicted;
}
Пример #7
0
void DList::Remove(DataType d)
{
	Node *cur = _head;
	int ret = Find(d);
	if (ret == 0)
	{
		PopFront();
		return;
	}
	while (ret--)
	{
		if (cur == NULL)
			return;
		cur = cur->_next;
	}
	if (cur != NULL)
	{
		if (cur == _tail)
		{
			PopBack();
		}
		else
		{
			Node *tmp = cur;
			(cur->_prev)->_next = cur->_next;
			delete tmp;
			tmp = NULL;
		}
	}
}
Пример #8
0
void Test2()
{
	Seq seq;
	InitSeqList(&seq);
	PushFront(&seq, 1);
	PushFront(&seq, 2);
	PushFront(&seq, 3);
	PushFront(&seq, 4);
	PushFront(&seq, 5);

	PopFront(&seq);
	PopFront(&seq);
	PopFront(&seq);
	PopFront(&seq);
//	PopFront(&seq);
//	PopFront(&seq);

	PrintSeqList(&seq);
}
void Scan(char** map,QUEUE *q,ROBOT *robot,int feu,char carac){

int i;
//le vecteur va permettre le deplacement a droite {1,0} a gauche {0,-1} en bas {-1,0} en haut {0,1}
//c'est l'ordre du pathfinding donc des fois pour les checkpoints le robot a un deplacement bizarre
int vec[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

//remet la queue au debut

q->front = q->back = 0;

//envoit les coordonnees dans le Tab de queue
PushBack(q,robot->pos);
//tant que le back est plus petit ou egale que le front
// == si il n'a plus rien a checker (ref popfront et pushback)
while(!(q->back <= q->front)){
	//conserve l'indice du Tab pour apres le mettre dans le from si l'indice est bon
    int from = q->front;
	//recupere les dernieres coordonnees du Tab
    COORDONNEES current = PopFront(q);
    for(i=0;i<4;i++){
        COORDONNEES sonde;
        sonde.x = current.x + vec[i][0];
        sonde.y = current.y + vec[i][1];
		//les cases dispo de passage sont ' ', '1','2','3' et 'i'
        if ((GetCase(map,sonde) == ' '||GetCase(map,sonde) == 'i'||GetCase(map,sonde) == '1'||GetCase(map,sonde) == carac||GetCase(map,sonde) == 			'2'||GetCase(map,sonde) == '3')&&!feu){

			//garde les bons indices pour afficher le chemin
			q->from[q->back] = from;
			//rentre la coordonnee dans le tableau
       		PushBack(q,sonde);	
			if (GetCase(map,sonde) == carac){
				return;//carac choisi arrive
			}
			//marque la case pour ne pas revenir dessus
			SetCase(map,sonde,'.');
		}
		//si le robot connait la config du feu alors il prend les 2 et les 3 comme des murs
		//donc carac de passage ' ','i'et '1'
		else if ((GetCase(map,sonde) == ' '||GetCase(map,sonde) == 'i'||GetCase(map,sonde) == '1'||GetCase(map,sonde) == carac)&&feu){
			
			//garde les bons indices pour afficher le chemin
			q->from[q->back] = from;
			//rentre la coordonnee dans le tableau
        	PushBack(q,sonde);	
			if (GetCase(map,sonde) == carac){
				return;//carac choisi arrive
			}
		//marque la case pour ne pas revenir dessus
		SetCase(map,sonde,'.');
        }
    }
}
return;
}
Пример #10
0
 Request* Get(
     int inBufferCount)
 {
     int theReqCount = GetReqListSize(inBufferCount);
     if (mFreeCount < theReqCount) {
         return 0;
     }
     Request* const theRetPtr = PopFront(kFreeQueueIdx);
     if (! theRetPtr) {
         return theRetPtr;
     }
     mFreeCount--;
     while (--theReqCount > 0) {
         Request* const thePtr = PopFront(kFreeQueueIdx);
         QCASSERT(thePtr);
         Insert(*theRetPtr, *thePtr);
         mFreeCount--;
     }
     return theRetPtr;
 }
Пример #11
0
 /*!
  * Reconstruct the buffer to be a copy of a subrange of an existing buffer.
  *
  *  @param[in] other    The contents of this buffer are copied.
  *  @param[in] off      This buffer starts at \a off bytes from the start of \a other.
  *                       If \a off is larger than \a other, the new buffer is empty.
  */
 void Assign(const DATA &other, size_t off=0)
 {
     if (this != &other)
     {
         DetachBuf();
         CopyFromData(other, off);
     }
     else
     {
         PopFront(off);
     }
 }
Пример #12
0
uint32_t
ResourceQueue::EvictAll()
{
  SBR_DEBUG("EvictAll()");
  uint32_t evicted = 0;
  while (ResourceItem* item = ResourceAt(0)) {
    SBR_DEBUG("item=%p length=%d offset=%llu",
              item, item->mData->Length(), mOffset);
    mOffset += item->mData->Length();
    evicted += item->mData->Length();
    delete PopFront();
  }
  return evicted;
}
Пример #13
0
 /*!
  * Reconstruct the buffer to be a copy of a subrange of an existing buffer.
  *
  *  @param[in] other    The contents of this buffer are a copy of the contents of \a other.
  *  @param[in] off      This buffer starts at \a off bytes from the start of \a other.
  *                       If \a off is larger than \a other, the new buffer is empty.
  *  @param[in] len      This buffer is at most \a len bytes long.  If \a off + \a len
  *                       is greater than the length of \a other, the new buffer is a copy
  *                       of the data up to the end of \a other.
  */
 void Assign(const DATA &other, size_t off, size_t len)
 {
     if (this != &other)
     {
         DetachBuf();
         CopyFromDataWithLen(other, off, len);
     }
     else
     {
         PopFront(off);
         if (len < _size)
             _size = len;
     }
 }
Пример #14
0
ConditionVariable::Event::~Event() {
    if (0 == handle_) {
        // This is the list holder
        while (!IsEmpty()) {
            Event* cv_event = PopFront();
            //DCHECK(cv_event->ValidateAsItem());
            delete cv_event;
        }
    }
    //DCHECK(IsSingleton());
    if (0 != handle_) {
        int ret_val = CloseHandle(handle_);
        //DCHECK(ret_val);
    }
}
Пример #15
0
void DescriptorAllocator::FreeTemporaryAllocations() {
	while (Size(PendingTemporaryBlocks)) {
		if (IsFenceCompleted(Blocks[Front(PendingTemporaryBlocks)].fence)) {
			auto index = Front(PendingTemporaryBlocks);
			PopFront(PendingTemporaryBlocks);
			PushBack(TemporaryBlocks, index);
			Blocks[index].fence = {};
			Blocks[index].next_allocation_offset = 0;
		}
		else {
			break;
		}
	}
	CurrentTemporaryBlockIndex = 0;
}
Пример #16
0
int TItemList::Reduce(int length)
{
	int remain = length;

	while(remain > 0 && Size() > 0)
	{
		TItem* pItem = Front();
		remain		-= pItem->Reduce(remain);

		if(pItem->IsEmpty())
			itPool.PutFreeItem(PopFront());
	}

	return length - remain;
}
Пример #17
0
OSCondVarOld::Event::~Event()
{
    if (0 == handle_)
    {
        while (!IsEmpty())
        {
            Event *cv_event = PopFront();
            delete cv_event;
        }
    }
    if (0 != handle_)
    {
        int ret_val = CloseHandle(handle_);
    }
}
Пример #18
0
void *consum(void* arg)
{
	while(1)
	{
	  pthread_mutex_lock(&lock);
	  while(isempty(head))
	  {
	     pthread_cond_wait(&cond,&lock);
	  }
	  int data=0;
	  PopFront(head,&data);
	  printf("%x: %d\n",pthread_self(),data);
	  
	  pthread_mutex_unlock(&lock);
	  sleep(1);
	}

}
Пример #19
0
int TItemList::Fetch(BYTE* pData, int length)
{
	int remain = length;

	while(remain > 0 && Size() > 0)
	{
		TItem* pItem = Front();
		int fetch	 = pItem->Fetch(pData, remain);

		pData	+= fetch;
		remain	-= fetch;

		if(pItem->IsEmpty())
			itPool.PutFreeItem(PopFront());
	}

	return length - remain;
}
Пример #20
0
	virtual void run()
	{
#ifdef _XBOX
		XSetThreadProcessor(GetCurrentThread(), _processorNo);
#endif
		Thread::yield();

		LOG(0, "&& AsyncLoader @%d: started\n", CurrentProcessorNo());

		while (!_terminated)
		{
			_mutex.lock();
			_current = NULL;
			PopFront(_current);
			_mutex.unlock();

			if (_current == NULL)
			{
				LOG(0, "&& AsyncLoader @%d: idle\n", CurrentProcessorNo());
				_queueReady.wait();
				continue;
			}

			LOG(0, "&& AsyncLoader @%d: pick-up '%s'\n", CurrentProcessorNo(), _current->getName().c_str());

			try
			{
				_current->prepare(true);
			}
			catch (...)
			{
				LOG(0, "&& AsyncLoader @%d: Terminated due to an exception.\n", CurrentProcessorNo());
#ifdef _XBOX
				XLaunchNewImage( XLAUNCH_KEYWORD_DASH_ARCADE, 0 );
				return;
#endif				
			}

			LOG(0, "&& AsyncLoader @%d: output '%s'\n", CurrentProcessorNo(), _current->getName().c_str());
			AddOutput(_current);
		}

		LOG(0, "&& AsyncLoader @%d: terminated\n", CurrentProcessorNo());
	}
Пример #21
0
void ValuesTable::Move(const Interval &in) {
	if (in.End() < 0 || in.Start() >= (int)m_values.size()) {
		m_values.resize(0);
		m_values.resize(in.End() - in.Start() + 1);
		return;
	}

	while ((in.End() + 1) < (int)m_values.size())
		PopBack();

	for (int i = 0; i < in.Start(); ++i)
		PopFront();

	for (int i = 0; i > in.Start(); --i)
		PushFront();

	for (int i = m_values.size(); i <= in.End() - in.Start(); ++i) 
		PushBack();
}
Пример #22
0
void *consum1(void* arg)
{
	while(pthread_mutex_lock(&_lock)==0)
	{while(1)
	{
	  pthread_mutex_lock(&lock);
	  while(isempty(head))
	  {
	     pthread_cond_wait(&cond,&lock);
	  }
	  int data=0;
	  PopFront(head,&data);
	  printf("th1: %d\n",data);
	  
	  pthread_mutex_unlock(&lock);
	  pthread_mutex_unlock(&_lock);
	  sleep(1);
	}
	}

}
Пример #23
0
void test1()
{
	LinkList list;
	InitLinkList(&list);
	PushBack(&list, 1);
	PushBack(&list, 2);
	PushBack(&list, 3);
	PushBack(&list, 4);
	PushBack(&list, 5);
	PopBack(&list);
	PopBack(&list);
	PopBack(&list);
	PrintList(&list);
	PushFront(&list, 6);
	PushFront(&list, 7);
	PushFront(&list, 8);
	PrintList(&list);
	PopFront(&list);
	PrintList(&list);
	DestoryLinkList(&list);
	PrintList(&list);
}
Пример #24
0
	void DeleteAt(uword indx)
	{
		Item[indx] = Item[Front];
		PopFront();
	}
Пример #25
0
void List<T>::Clear()
// Deletes all elements of the list
{
  while (!Empty())
    PopFront();
} // end Clear()
Пример #26
0
List<T>::~List()
{
	while (first != nullptr && last != nullptr) {
		PopFront();
	}
}