void CreateEmpty (Queue * Q, int Max) {
	/*Algoritma*/
	(*Q).T = (infotype*) malloc (Max * sizeof (infotype));
	MaxEl(*Q) = Max-1;
	if ((*Q).T == NULL) {
		(*Q).T = (infotype*) malloc (1 * sizeof (infotype));
		MaxEl(*Q) = 1;
	}
	Head(*Q) = Nil; 
	Tail(*Q) = Nil;
}
Пример #2
0
/*  Mengirimkan banyaknya elemen PQueue. Mengirimkan 0 jika Q kosong.  */
int NBElmtPQ (PQueue Q)
{
	addressPQ P=Head(Q);
	int total=0;
	while (P!=NilPQ)
	{
		++total;
		P=Next(P);
	}
	return total;
}
Пример #3
0
/* *** Operator-Operator Dasar Queue *** */
void Add (Queue *Q, infotype X)
/* Proses : Menambahkan  X pada Q dengan aturan FIFO */
/* I.S. Q mungkin kosong, tabel penampung elemen Q TIDAK penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" */
{
    if(IsEmpty(*Q))
    {
        Head(*Q)=1;
    }
    Tail(*Q)++;
    InfoTail(*Q)=X;
}
Пример #4
0
void RenderSystemProcess(World world, IntrusiveList entities) {
    IntrusiveListNodePtr iter = Next(Head(entities));
    IntrusiveListNodePtr head = Head(entities);

    while (iter != head) {
        Entity entity = container_of(iter, struct entity, renderSystemListNode);

        PositionComponent positionComponent = GetComponentByType(world, entity, POSITION)->positionComponent;
        SpriteComponent spriteComponent = GetComponentByType(world, entity, SPRITE)->spriteComponent;

        SDL_Rect heroPos;
        heroPos.h = 32;
        heroPos.w = 32;
        heroPos.x = 32*positionComponent->x;
        heroPos.y = 32*positionComponent->y;

        SDL_BlitSurface(spriteComponent->image->bitmap->surface, NULL, SDL_GetVideoSurface(), &heroPos);

        iter = Next(iter);
    }
}
Пример #5
0
Файл: evalf.cpp Проект: mulab/mU
var Evalf(Var x)
{
	switch(Type(x))
	{
	case TYPE(int):
		{
			var r = Flt();
			F::SetZ(r,x);
			return r;
		}
		break;
	case TYPE(rat):
		{
			var r = Flt();
			F::SetQ(r,x);
			return r;
		}
		break;
	case TYPE(flt):
		{
			var r = Flt();
			F::Set(r,x);
			mpf_set_prec(CFlt(r),mpf_get_default_prec());
			return r;
		}
		break;
	case TYPE(sym):
		{
			std::map<Var,attr_t>::const_iterator
				iter = Attributes.find(x);
			if(iter != Attributes.end() &&
				iter->second.count(Constant))
				return CProcs[x](0);
		}
		break;
	case TYPE(vec):
		{
			size_t n = Size(x);
			var r = Vec(n);
			for(size_t i = 0; i < n; ++i)
				At(r,i) = Evalf(At(x,i));
			return r;
		}
		break;
	case TYPE(ex):
		{
			var b = Evalf(Body(x));
			return Eval(Ex(Head(x),b));
		}
		break;
	}
	return x;
}
Пример #6
0
void Add(Queue *Q, infotype_dadu X)
/* Menambahkan X sebagai elemen Queue Q */
/* I.S. Q mungkin kosong, tabel penampung elemen Q tidak penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" */
{
    if (IsEmpty(*Q))
    {
        Head(*Q) = 1;
    }
    Tail(*Q)++;
    InfoTail(*Q) = X;
}
Пример #7
0
/*
============
idBrushList::GetBounds
============
*/
idBounds idBrushList::GetBounds() const
{
	idBounds bounds;
	idBrush* b;
	
	bounds.Clear();
	for( b = Head(); b; b = b->Next() )
	{
		bounds += b->GetBounds();
	}
	return bounds;
}
Пример #8
0
void Del (Queue *Q,infotype *X)
/* Proses  Menghapus elemen pertama pada Q dengan aturan FIFO */
/* I.S. Q tidak kosong */
/* F.S. X = nilai elemen HEAD pada I.S.,
Jika Queue masih isi  HEAD "maju".
Jika HEAD baru menjadi MaxEl + 1, maka HEAD diset = 1;
Jika Queue menjadi kosong, HEAD = TAIL = Nil. */
{
	/*kamus lokal*/

	/*algoritma*/  
		(*X) = InfoHead(*Q);
		if (Head(*Q) == Tail(*Q))	{
			Head(*Q) = Nil;
			Tail(*Q) = Nil;
		}
		else {	
			Head(*Q)++;
			if (Head(*Q) == MaxEl(*Q) + 1) Head(*Q) = 1;
		}
}
Пример #9
0
/*
============
idBrushList::Merge
============
*/
void idBrushList::Merge( bool ( *MergeAllowed )( idBrush* b1, idBrush* b2 ) )
{
	idPlaneSet planeList;
	idBrush* b1, *b2, *nextb2;
	int numMerges;
	
	common->Printf( "[Brush Merge]\n" );
	common->Printf( "%6d original brushes\n", Num() );
	
	CreatePlaneList( planeList );
	
	numMerges = 0;
	for( b1 = Head(); b1; b1 = b1->next )
	{
	
		for( b2 = Head(); b2; b2 = nextb2 )
		{
			nextb2 = b2->Next();
			
			if( b2 == b1 )
			{
				continue;
			}
			
			if( MergeAllowed && !MergeAllowed( b1, b2 ) )
			{
				continue;
			}
			
			if( b1->TryMerge( b2, planeList ) )
			{
				Delete( b2 );
				DisplayRealTimeString( "\r%6d", ++numMerges );
				nextb2 = Head();
			}
		}
	}
	
	common->Printf( "\r%6d brushes merged\n", numMerges );
}
Пример #10
0
static void showQueueContent (Queue *Q) {
	int i;
	Student S;
	for(i=0;i<Size(Q);i++) {
		Head(Q, &S);
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}
	for(i = 0;i<Size(Q);i++) {
		Tail(Q, &S);
		FreeStudent(&S);
	}
}
Пример #11
0
void PrintSkor(Queue *Q)
/* I.S : Queue tidak kosong */
/* F.S : Menampilkan seluruh skor pemain sesuai dengan format yang telah ditentukan */
{
	int i;
	for (i = Head(*Q); i <= Tail(*Q); i++)
	{
		printf("%s : %d", InfoHeadNama(*Q), InfoHeadSkor(*Q));
		printf("  ");
		ChangeTurn(&(*Q));
	}
	printf("\n");
}
Пример #12
0
void Del(Queue *Q, infotypeQueue *X)
/* Proses: Menghapus X pada Q dengan aturan FIFO */
/* I.S. Q tidak mungkin kosong */
/* F.S. X = nilai elemen HEAD pd I.S., HEAD "maju" dengan mekanisme circular buffer; 
        Q mungkin kosong */
{
    *X = InfoHead(*Q);

    if (Head(*Q) == Tail(*Q))
    {
        Head(*Q) = 0;
        Tail(*Q) = 0;
    }
    else if (Head(*Q) == MaxEl(*Q))
    {
        Head(*Q) = 1;
    }
    else
    {
        ++Head(*Q);
    }
}
Пример #13
0
//____________________________________________________________
void TRemoteMgr::CheckTimeOut (unsigned long date)
{
	RemotePtr r = Head();
	RemotePtr prev = 0, next;
	while (r) {
		next = r->next;
		if (r->timeOut < date) {
			Remove (r->remote->GetID());
		}
		else prev = r;
		r = next;
	}
}
Пример #14
0
const SimpleNode<T>* ConstListIterator<T>::IndexNode(size_t Index_)
{
  if (Index_ < Count())
  {
    Head();
    for (size_t Count_ = 0; _ConstList && Count_ < Index_; Count_++)
      ++(*this);
  }
  else
    return NULL;

  return _ConstHere;
}
Пример #15
0
int NBElmt (Queue Q)
/* Mengirimkan banyaknya elemen queue. Mengirimkan 0 jika Q kosong. */
{ /* Kamus Lokal */
	int count;
	address P;
/* Algoritma */
	count=0;
	P=Head(Q);
	while(P!=Nil) {
		count=count+1;
		P=Next(P);
	}
	return(count);
}
Пример #16
0
void Add (Queue *Q,infotype X)
{
	if (IsEmpty(*Q))
	{
		Tail(*Q) = 1;
		Head(*Q) = 1;
	}
	else
	{
		Tail(*Q) += 1;
		if (Tail(*Q) == (*Q).MaxEl + 1) Tail(*Q) = 1;
	}
	InfoTail(*Q) = X;
}
Пример #17
0
//____________________________________________________________
Boolean TRemoteMgr::Refresh (IPNum id, PeerTimesPtr times)
{
	RemotePtr r = Head();
	while (r) {
		if (r->remote->GetID() == id) {
			TMidiRemote * m = (TMidiRemote *)r->remote;
			r->timeOut = times->local + kRemoteTTL;
			m->CheckLatency (times);
			return true;
		}
		r = r->next;
	}
	return false;
}
Пример #18
0
// Step
void
PolygonQueue::Step()
{
	if (Polygon* p = Head()) {
		Polygon *np = p->Step();
		// drop tail
		delete Tail();
		// shift
		for (int32 i = 0; i < fDepth - 1; i++)
			fPolygons[i] = fPolygons[i + 1];
		// and put new head at top
		fPolygons[fDepth - 1] = np;
	}
}
Пример #19
0
void Del(Queue *Q, infotype_dadu *X)
/* Menghapus elemen pertama pada Q */
/* I.S. Q tidak kosong */
/* F.S. X = nilai elemen HEAD pada I.S., */
/*      JIka Queue masih isim HEAD diset tetap = 1, elemen-elemen setelah HEAD YANG */
/*      lama digeser ke "kiri", TAIL = TAIL - 1 */
/*      Jika Queue menjadi kosog, HEAD = TAIL = Nil */
{
    int i;
    *X = InfoHead(*Q);
    if (Head(*Q) == Tail(*Q))
    {
        Head(*Q) = Nil;
        Tail(*Q) = Nil;
    }
    else
    {
        for (i = 1; i < Tail(*Q); i++)
        {
            *((*Q).T+i) = *((*Q).T+i+1);
        }
        Tail(*Q) = Tail(*Q) - 1;
    }
}
Пример #20
0
SimpleNode<T>* SimpleListIterator<T>::Update(size_t Index_, T* Data_)
{
  if (Index_ < Count())
  {
    Head();
    for (size_t Count_ = 0; _List && Count_ < Index_; Count_++)
      ++(*this);      

    ::Delete(_Here->_Object);
    _Here->_Object = Data_;
  }
  else
    return NULL;
  
  return _Here;
}
Пример #21
0
/*
============
idBrushList::CreatePlaneList
============
*/
void idBrushList::CreatePlaneList( idPlaneSet& planeList ) const
{
	int i;
	idBrush* b;
	idBrushSide* side;
	
	planeList.Resize( 512, 128 );
	for( b = Head(); b; b = b->Next() )
	{
		for( i = 0; i < b->GetNumSides(); i++ )
		{
			side = b->GetSide( i );
			side->SetPlaneNum( planeList.FindPlane( side->GetPlane(), BRUSH_PLANE_NORMAL_EPSILON, BRUSH_PLANE_DIST_EPSILON ) );
		}
	}
}
Пример #22
0
void XMLWriter::Write(QFile& file){
    QDomDocument doc;
    auto instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
    doc.appendChild(instruction);
    QDomElement root = doc.createElement("map");
    root.setAttribute("version","1.0");
    doc.appendChild(root);
    //Head
    Head(root);
    //Body
    Body(root);
    //写入到xml文件
    QTextStream out(&file);
    doc.save(out, 4);
    file.close();
}
Пример #23
0
void CVwsEventQueue::KickStart()
	{
	//Attempt to restart stalled q
	DeleteHead();
	iState=EEmpty;
	TInt err = KErrGeneral;
	while(iQueueSize>0 && err)
		{
		iState=EProcessing;
		TRAP(err, Head()->ProcessEventL());
		if (err)
			{
			DeleteHead();
			iState=EEmpty;
			}
		}
	}
Пример #24
0
        INLINE int PopTail()
        {   
            AtomicCounter old_val;
            AtomicCounter new_val;

            do {
                old_val = fCounter;
                new_val = old_val;
                if (Head(old_val) == Tail(old_val)) {
                    return WORK_STEALING_INDEX;
                } else {
                    IncTail(new_val);
                }
            } while (!CAS1(&fCounter, Value(old_val), Value(new_val)));

            return fTaskList[Tail(old_val)];
        }
Пример #25
0
/**** PROSES SEMUA ELEMEN QUEUE *****/
void PrintInfo (Queue Q)
/* I.S. queue mungkin kosong */
/* F.S. Jika queue tidak kosong, */
/* Semua info yg disimpan pada elemen queue diprint */
/* Jika queue kosong, hanya menuliskan "queue kosong" */
{/*Kamus Lokal */
	address P;
/* Algoritma */
	if(IsPrioQueueEmpty(Q)) printf("Queue kosong\n");
	else {
		P=Head(Q);
		while(P!=Nil) {
			printf("%d ",Info(P));
			P=Next(P);
		}
		printf("\n");
	}
}
Пример #26
0
void CreateEmpty(Queue *Q, int Max)
/* I.S. Sembarang */
/* F.S. Sebuah Q kosong terbentuk dan salah satu kondisi sbb: */
/* Jika alokasi berhasil, Tabel memori dialokasi berukuran Max */
/* atau : jika alokasi gagal, Q kosong dgn MaxEl = 0 */
/* Proses : Melakukan alokasi, membuat sebuah Q kosong */
{
    (*Q).T = (infotype_dadu *) malloc ((Max+1) * sizeof(infotype_dadu));
    if ((*Q).T != NULL)
    {
        MaxEl(*Q) = Max;
        Head(*Q) = Nil;
        Tail(*Q) = Nil;
    }
    else
    {
        MaxEl(*Q) = Nil;
    }
}
Пример #27
0
/* *** Konstruktor *** */
void CreateEmpty (Queue *Q, int Max)
/* I.S. Max terdefinisi */
/* F.S. Sebuah Q kosong terbentuk dan salah satu kondisi sbb :       */
/*      Jika alokasi berhasil, tabel memori dialokasi berukuran Max  */
/*      atau : jika alokasi gagal, Q kosong dg Maksimum elemen=0     */
/* Proses : Melakukan alokasi memori dan membuat sebuah Q kosong     */
{
    (*Q).T = (infotype *) malloc((Max+1)*sizeof(infotype));
    if ((*Q).T != Nil)
    {
        MaxEl(*Q) = Max;
        Head(*Q) = Nil;
        Tail(*Q) = Nil;
    }
    else /* alokasi gagal */
    {
        MaxEl(*Q)=Nil;
    }
}
Пример #28
0
static void showQueueContent (Queue *L) 
{
	int i;
	Student S;
    int realHead = L->head;
    //loop transverses through queue via head
	for(i=0;i<Length(L);i++) 
    {
        //circulates array if maxsize is reached
        if (L->head == MAXLISTSIZE)  
        {
            L->head = 0;
        }
		Head(L,&S); //gets head of queue
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
        L->head++;   
	}
    L->head = realHead; //fixes the head
}
Пример #29
0
data_string::data_string(char *str) :size(0), _fill(0)
{
	if (str == NULL)
		return;
	char * tmp = str;
	while (*tmp++ != '\0') this->size++;

	this->str = new char[this->size + 1];
	if (this->str == NULL)
		throw("Error alloc memory");

	tmp = str;
	for (size_t i = 0; i<=this->size; i++, tmp++)
		this->str[i] = *tmp;

	this->_fill = this->lenght();

	Head(this->str);
	Last(this->str + this->fill());
	Tail(this->str + this->lenght());
}
Пример #30
0
/* *** Primitif Add/Delete *** */
void Add(Queue *Q, infotypeQueue X)
/* Proses: Menambahkan X pada Q dengan aturan FIFO */
/* I.S. Q mungkin kosong, tabel penampung elemen Q TIDAK penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" dengan mekanisme circular buffer */
{
    if (IsEmptyQueue(*Q))
    {
        Head(*Q) = 1;
        Tail(*Q) = 1;
    }
    else if (Tail(*Q) == MaxEl(*Q))
    {
        Tail(*Q) = 1;
    }
    else
    {
        ++Tail(*Q);
    }

    InfoTail(*Q) = X;
}