diff --git a/.gitattributes b/.gitattributes index 5f55dccf6fee54ec1f78d33b311f71530eef1bab..956f086e8f9509668b0ed2e950c38053038ce3f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/lib/modules/ADT.pmod/Queue.pike b/lib/modules/ADT.pmod/Queue.pike new file mode 100644 index 0000000000000000000000000000000000000000..5a19a27a456ac094c6cef644cea77347f7cb50d7 --- /dev/null +++ b/lib/modules/ADT.pmod/Queue.pike @@ -0,0 +1,66 @@ +/* $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(); +}