Skip to content
Snippets Groups Projects
Commit 8c61858f authored by Per Hedbor's avatar Per Hedbor
Browse files

New name, and now uses the same API as Thread.Queue, which is rather useful

Rev: lib/modules/ADT.pmod/Queue.pike:1.1
parent 1bfc6dca
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ testfont binary
/bin/pikedoc2.pike foreign_ident
/bin/test_pike.pike foreign_ident
/lib/master.pike.in foreign_ident
/lib/modules/ADT.pmod/Queue.pike foreign_ident
/lib/modules/ADT.pmod/Table.pmod foreign_ident
/lib/modules/Crypto/des3.pike foreign_ident
/lib/modules/Crypto/des3_cbc.pike foreign_ident
......
/* $Id: Queue.pike,v 1.1 1999/11/29 18:24:24 per Exp $
*
* A simple FIFO queue.
*/
#define QUEUE_SIZE 100
array l;
int head;
int tail;
void create(mixed ...args)
{
l = args + allocate(QUEUE_SIZE);
head = sizeof(args);
tail = 0;
}
void write(mixed item)
{
put(item);
}
void put(mixed item)
{
if (head == sizeof(l))
{
l = l[tail ..];
head -= tail;
tail = 0;
l += allocate(sizeof(l) + QUEUE_SIZE);
}
l[head++] = item;
// werror(sprintf("Queue->put: %O\n", l[tail..head-1]));
}
mixed read()
{
return get();
}
mixed get()
{
// werror(sprintf("Queue->get: %O\n", l[tail..head-1]));
mixed res;
if (tail == head)
return ([])[0];
res = l[tail];
l[tail++] = 0;
return res;
}
mixed peek()
{
return (tail < head) && l[tail];
}
int is_empty()
{
return (tail == head);
}
void flush()
{
create();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment