<commit_before>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2012  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kernel/access.h>

#include <kotaka/assert.h>
#include <kotaka/paths.h>
#include <kotaka/privilege.h>
#include <kotaka/log.h>

#include <kotaka/bigstruct.h>

inherit "../base/root";

object first;
object last;

void dump();

atomic static void create()
{
	::create();

	first = last = new_node();
}

static void destruct()
{
	while (first) {
		object turkey;
		turkey = first;
		first = first->get_next();
		discard_node(turkey);
	}
}

mixed get_front()
{
	check_caller(READ_ACCESS);

	return first->get_front();
}

mixed get_back()
{
	check_caller(READ_ACCESS);

	return last->get_back();
}

void set_front(mixed value)
{
	check_caller(WRITE_ACCESS);

	first->set_front(value);
}

void set_back(mixed value)
{
	check_caller(WRITE_ACCESS);

	last->set_back(value);
}

atomic void push_front(mixed value)
{
	check_caller(WRITE_ACCESS);

	if (first->full_front()) {
		object new;

		new = new_node();

		first->set_prev(new);
		new->set_next(first);
		first = new;
	}

	first->push_front(value);
}

atomic void push_back(mixed value)
{
	check_caller(WRITE_ACCESS);

	if (last->full_back()) {
		object new;

		new = new_node();

		last->set_next(new);
		new->set_prev(last);
		last = new;
	}

	last->push_back(value);
}

atomic void pop_front()
{
	check_caller(WRITE_ACCESS);

	first->pop_front();

	if (first->get_mass() == 0 && first != last) {
		object old;

		old = first;
		first = first->get_next();
		old->set_next(nil);

		discard_node(old);
	}
}

atomic void pop_back()
{
	check_caller(WRITE_ACCESS);

	last->pop_back();

	if (last->get_mass() == 0 && first != last) {
		object old;

		old = last;
		last = last->get_prev();

		discard_node(old);
	}
}

int empty()
{<commit_msg>Fixed bug where empty end was left behind during single mass queue cycles<commit_after>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2012  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kernel/access.h>

#include <kotaka/assert.h>
#include <kotaka/paths.h>
#include <kotaka/privilege.h>
#include <kotaka/log.h>

#include <kotaka/bigstruct.h>

inherit "../base/root";

object first;
object last;

void dump();

private void trim_first()
{
	if (first->get_mass() == 0 && first != last) {
		object old;

		old = first;
		first = first->get_next();
		old->set_next(nil);

		discard_node(old);
	}
}

private void trim_last()
{
	if (last->get_mass() == 0 && first != last) {
		object old;

		old = last;
		last = last->get_prev();

		discard_node(old);
	}
}

atomic static void create()
{
	::create();

	first = last = new_node();
}

static void destruct()
{
	while (first) {
		object turkey;
		turkey = first;
		first = first->get_next();
		discard_node(turkey);
	}
}

mixed get_front()
{
	check_caller(READ_ACCESS);

	return first->get_front();
}

mixed get_back()
{
	check_caller(READ_ACCESS);

	return last->get_back();
}

void set_front(mixed value)
{
	check_caller(WRITE_ACCESS);

	first->set_front(value);
}

void set_back(mixed value)
{
	check_caller(WRITE_ACCESS);

	last->set_back(value);
}

atomic void push_front(mixed value)
{
	check_caller(WRITE_ACCESS);

	if (first->full_front()) {
		object new;

		new = new_node();

		first->set_prev(new);
		new->set_next(first);
		first = new;
	}

	trim_last();
	first->push_front(value);
}

atomic void push_back(mixed value)
{
	check_caller(WRITE_ACCESS);

	if (last->full_back()) {
		object new;

		new = new_node();

		last->set_next(new);
		new->set_prev(last);
		last = new;
	}

	last->push_back(value);
	trim_first();
}

atomic void pop_front()
{
	check_caller(WRITE_ACCESS);

	first->pop_front();
	trim_first();
}

atomic void pop_back()
{
	check_caller(WRITE_ACCESS);

	last->pop_back();
	trim_last();
}

int empty()
{
{'fraction_non_alphanumeric': 0.1347449470644851, 'fraction_numerical': 0.002694898941289702, 'mean_word_length': 4.03000968054211, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6333809', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1806, 'n_words': 518}