<commit_before>// vim:syntax=lpc

#if Q == 1
# define QUEUE		MMP.Utils.Queue
# define ENQUEUE(x,y)	(x)->push(y)
# define SHIFT(x)	(x)->shift()
# define ISEMPTY(x)	(x)->isEmpty()
# define SIZEOF(x)	sizeof(x)
# define INIT()		QUEUE()
#elif Q == 2
mixed t;
# define QUEUE		array
# define ENQUEUE(x,y)	((x) += ({ (y) }))
# define SHIFT(x)	(t = (x)[0], (x) = (x)[1..], t)
# define ISEMPTY(x)	(sizeof(x) == 0)
# define SIZEOF(x)	sizeof(x)
# define INIT()		allocate(0)
#elif Q == 3
# define QUEUE ADT.Queue
# define ENQUEUE(x,y)	(x)->put(y)
# define SHIFT(x)	(x)->get()
# define ISEMPTY(x)	(x)->is_empty()
# define SIZEOF(x)	sizeof((array)x)
# define INIT()		QUEUE()
#endif

void test1() {
    QUEUE q = INIT();

    for (int i = 1000; i > 0; i--) {
	for (int j = 0; j < i; j++) {
	    if (i & 1) {
		SHIFT(q);
	    } else {
		ENQUEUE(q, j + i);
	    }
	}
    }

    //write("sizeof(q): %d\n", SIZEOF(q));

#if 0
    while (!ISEMPTY(q)) {
	SHIFT(q);
    }
#endif
}

void test2() {
    QUEUE q = INIT();

    for (int i = 0; i < 100000; i++) {
	ENQUEUE(q, i);
    }

    while (!ISEMPTY(q)) {
	SHIFT(q);
    }
}

void test3() {
    QUEUE q = INIT();

    for (int i = 0; i < 10000; i++) {
	ENQUEUE(q, i);
	SHIFT(q);
    }
}

void ttest(function test) {
    int begin = time();
    float bo = time(begin);

    test();

    write("timed: %.032f\n", time(begin)-bo);
}

int main() {
    array tests = ({ test1, test2, test3 });

    ttest(tests[*]);

    return 0;
}
<commit_msg>new way of doing queues (a more comparable "direct array" solution, object-encapsulated).<commit_after>// vim:syntax=lpc

#if Q == 1 || Q == 2
# if Q == 2
class Queue {
    array _ = ({ });

    void push(mixed x) {
	_ += ({ x });
    }

    mixed shift() {
	mixed x;

	x = _[0];
	_ = _[1..];
    }

    int isEmpty() {
	return sizeof(_) == 0;
    }

    int _sizeof() {
	return sizeof(_);
    }
}

#  define QUEUE		Queue
# else
#  define QUEUE		MMP.Utils.Queue
# endif
# define ENQUEUE(x,y)	(x)->push(y)
# define SHIFT(x)	(x)->shift()
# define ISEMPTY(x)	(x)->isEmpty()
# define SIZEOF(x)	sizeof(x)
# define INIT()		QUEUE()
#elif Q == 3
mixed t;
# define QUEUE		array
# define ENQUEUE(x,y)	((x) += ({ (y) }))
# define SHIFT(x)	(t = (x)[0], (x) = (x)[1..], t)
# define ISEMPTY(x)	(sizeof(x) == 0)
# define SIZEOF(x)	sizeof(x)
# define INIT()		allocate(0)
#elif Q == 4
# define QUEUE ADT.Queue
# define ENQUEUE(x,y)	(x)->put(y)
# define SHIFT(x)	(x)->get()
# define ISEMPTY(x)	(x)->is_empty()
# define SIZEOF(x)	sizeof((array)x)
# define INIT()		QUEUE()
#endif

void test1() {
    QUEUE q = INIT();

    for (int i = 1000; i > 0; i--) {
	for (int j = 0; j < i; j++) {
	    if (i & 1) {
		SHIFT(q);
	    } else {
		ENQUEUE(q, j + i);
	    }
	}
    }

    //write("sizeof(q): %d\n", SIZEOF(q));

#if 0
    while (!ISEMPTY(q)) {
	SHIFT(q);
    }
#endif
}

void test2() {
    QUEUE q = INIT();

    for (int i = 0; i < 100000; i++) {
	ENQUEUE(q, i);
    }

    while (!ISEMPTY(q)) {
	SHIFT(q);
    }
}

void test3() {
    QUEUE q = INIT();

    for (int i = 0; i < 10000; i++) {
	ENQUEUE(q, i);
	SHIFT(q);
    }
}

void ttest(function test) {
    int begin = time();
    float bo = time(begin);

    test();

    write("timed: %.032f\n", time(begin)-bo);
}

int main() {
    array tests = ({ test1, test2, test3 });

    ttest(tests[*]);

    return 0;
}

{'fraction_non_alphanumeric': 0.2202470623681832, 'fraction_numerical': 0.024404941247363664, 'mean_word_length': 2.6685082872928176, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3972366', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1475, 'n_words': 374}