/* updatequeue.c generated by valac 0.24.0, the Vala compiler
 * generated from updatequeue.vala, do not modify */

/* 
 * SmartSim - Digital Logic Circuit Designer and Simulator
 *   
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU 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 General Public License for more details.
 *   
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   Filename: list.vala
 *   
 *   Copyright Ashley Newson 2013
 */

#include <glib.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>


#define TYPE_UPDATE_QUEUE (update_queue_get_type ())
#define UPDATE_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UPDATE_QUEUE, UpdateQueue))
#define UPDATE_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UPDATE_QUEUE, UpdateQueueClass))
#define IS_UPDATE_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UPDATE_QUEUE))
#define IS_UPDATE_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UPDATE_QUEUE))
#define UPDATE_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UPDATE_QUEUE, UpdateQueueClass))

typedef struct _UpdateQueue UpdateQueue;
typedef struct _UpdateQueueClass UpdateQueueClass;
typedef struct _UpdateQueuePrivate UpdateQueuePrivate;
#define _elementtype_destroy_func0(var) (((var == NULL) || (elementtype_destroy_func == NULL)) ? NULL : (var = (elementtype_destroy_func (var), NULL)))
typedef struct _ParamSpecUpdateQueue ParamSpecUpdateQueue;

struct _UpdateQueue {
	GTypeInstance parent_instance;
	volatile int ref_count;
	UpdateQueuePrivate * priv;
	gpointer* elements;
	gint elements_length1;
};

struct _UpdateQueueClass {
	GTypeClass parent_class;
	void (*finalize) (UpdateQueue *self);
};

struct _UpdateQueuePrivate {
	GType elementtype_type;
	GBoxedCopyFunc elementtype_dup_func;
	GDestroyNotify elementtype_destroy_func;
	gint readUpdateTime;
	gint writeUpdateTime;
	gint* readTimes;
	gint readTimes_length1;
	gint _readTimes_size_;
	gint* writeTimes;
	gint writeTimes_length1;
	gint _writeTimes_size_;
	gint* readNexts;
	gint readNexts_length1;
	gint _readNexts_size_;
	gint* writeNexts;
	gint writeNexts_length1;
	gint _writeNexts_size_;
	gint readFirst;
	gint writeFirst;
	gint defaultFirst;
	gint currentElement;
};

struct _ParamSpecUpdateQueue {
	GParamSpec parent_instance;
};


static gpointer update_queue_parent_class = NULL;

gpointer update_queue_ref (gpointer instance);
void update_queue_unref (gpointer instance);
GParamSpec* param_spec_update_queue (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_update_queue (GValue* value, gpointer v_object);
void value_take_update_queue (GValue* value, gpointer v_object);
gpointer value_get_update_queue (const GValue* value);
GType update_queue_get_type (void) G_GNUC_CONST;
#define UPDATE_QUEUE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_UPDATE_QUEUE, UpdateQueuePrivate))
enum  {
	UPDATE_QUEUE_DUMMY_PROPERTY
};
UpdateQueue* update_queue_new (GType elementtype_type, GBoxedCopyFunc elementtype_dup_func, GDestroyNotify elementtype_destroy_func, gpointer* elements, int elements_length1, gpointer* permanentElements, int permanentElements_length1);
UpdateQueue* update_queue_construct (GType object_type, GType elementtype_type, GBoxedCopyFunc elementtype_dup_func, GDestroyNotify elementtype_destroy_func, gpointer* elements, int elements_length1, gpointer* permanentElements, int permanentElements_length1);
static gpointer* _vala_array_dup98 (gpointer* self, int length, GBoxedCopyFunc elementtype_dup_func);
void update_queue_add_permanent_element (UpdateQueue* self, gint elementNumber);
void update_queue_swap (UpdateQueue* self, gint newTime);
static gint* _vala_array_dup99 (gint* self, int length);
static gint* _vala_array_dup100 (gint* self, int length);
static gint* _vala_array_dup101 (gint* self, int length);
static gint* _vala_array_dup102 (gint* self, int length);
static gint* _vala_array_dup103 (gint* self, int length);
static gint* _vala_array_dup104 (gint* self, int length);
void update_queue_full_update (UpdateQueue* self);
void update_queue_add_element (UpdateQueue* self, gint elementNumber);
gpointer update_queue_get_next_element (UpdateQueue* self);
static void update_queue_finalize (UpdateQueue* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static gpointer* _vala_array_dup98 (gpointer* self, int length, GBoxedCopyFunc elementtype_dup_func) {
	gpointer* result;
	int i;
	result = g_new0 (gpointer, length);
	for (i = 0; i < length; i++) {
		gpointer _tmp0_ = NULL;
		_tmp0_ = ((self[i] != NULL) && (elementtype_dup_func != NULL)) ? elementtype_dup_func ((gpointer) self[i]) : ((gpointer) self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


UpdateQueue* update_queue_construct (GType object_type, GType elementtype_type, GBoxedCopyFunc elementtype_dup_func, GDestroyNotify elementtype_destroy_func, gpointer* elements, int elements_length1, gpointer* permanentElements, int permanentElements_length1) {
	UpdateQueue* self = NULL;
	gint numberOfElements = 0;
	gpointer* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gpointer* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gpointer* _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	gint _tmp3_ = 0;
	gint* _tmp4_ = NULL;
	gint _tmp5_ = 0;
	gint* _tmp6_ = NULL;
	gint _tmp17_ = 0;
	gint* _tmp18_ = NULL;
	gint _tmp19_ = 0;
	gint* _tmp20_ = NULL;
	gpointer* _tmp21_ = NULL;
	gint _tmp21__length1 = 0;
	gint _tmp33_ = 0;
	gint _tmp34_ = 0;
	gint _tmp35_ = 0;
	self = (UpdateQueue*) g_type_create_instance (object_type);
	self->priv->elementtype_type = elementtype_type;
	self->priv->elementtype_dup_func = elementtype_dup_func;
	self->priv->elementtype_destroy_func = elementtype_destroy_func;
	_tmp0_ = elements;
	_tmp0__length1 = elements_length1;
	numberOfElements = _tmp0__length1;
	_tmp1_ = elements;
	_tmp1__length1 = elements_length1;
	_tmp2_ = (_tmp1_ != NULL) ? _vala_array_dup98 (_tmp1_, _tmp1__length1, elementtype_dup_func) : ((gpointer) _tmp1_);
	_tmp2__length1 = _tmp1__length1;
	self->elements = (_vala_array_free (self->elements, self->elements_length1, (GDestroyNotify) elementtype_destroy_func), NULL);
	self->elements = _tmp2_;
	self->elements_length1 = _tmp2__length1;
	_tmp3_ = numberOfElements;
	_tmp4_ = g_new0 (gint, _tmp3_);
	self->priv->readTimes = (g_free (self->priv->readTimes), NULL);
	self->priv->readTimes = _tmp4_;
	self->priv->readTimes_length1 = _tmp3_;
	self->priv->_readTimes_size_ = self->priv->readTimes_length1;
	_tmp5_ = numberOfElements;
	_tmp6_ = g_new0 (gint, _tmp5_);
	self->priv->writeTimes = (g_free (self->priv->writeTimes), NULL);
	self->priv->writeTimes = _tmp6_;
	self->priv->writeTimes_length1 = _tmp5_;
	self->priv->_writeTimes_size_ = self->priv->writeTimes_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp7_ = FALSE;
			_tmp7_ = TRUE;
			while (TRUE) {
				gint _tmp9_ = 0;
				gint _tmp10_ = 0;
				gint* _tmp11_ = NULL;
				gint _tmp11__length1 = 0;
				gint _tmp12_ = 0;
				gint _tmp13_ = 0;
				gint* _tmp14_ = NULL;
				gint _tmp14__length1 = 0;
				gint _tmp15_ = 0;
				gint _tmp16_ = 0;
				if (!_tmp7_) {
					gint _tmp8_ = 0;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp7_ = FALSE;
				_tmp9_ = i;
				_tmp10_ = numberOfElements;
				if (!(_tmp9_ < _tmp10_)) {
					break;
				}
				_tmp11_ = self->priv->readTimes;
				_tmp11__length1 = self->priv->readTimes_length1;
				_tmp12_ = i;
				_tmp11_[_tmp12_] = -1;
				_tmp13_ = _tmp11_[_tmp12_];
				_tmp14_ = self->priv->writeTimes;
				_tmp14__length1 = self->priv->writeTimes_length1;
				_tmp15_ = i;
				_tmp14_[_tmp15_] = -1;
				_tmp16_ = _tmp14_[_tmp15_];
			}
		}
	}
	_tmp17_ = numberOfElements;
	_tmp18_ = g_new0 (gint, _tmp17_);
	self->priv->readNexts = (g_free (self->priv->readNexts), NULL);
	self->priv->readNexts = _tmp18_;
	self->priv->readNexts_length1 = _tmp17_;
	self->priv->_readNexts_size_ = self->priv->readNexts_length1;
	_tmp19_ = numberOfElements;
	_tmp20_ = g_new0 (gint, _tmp19_);
	self->priv->writeNexts = (g_free (self->priv->writeNexts), NULL);
	self->priv->writeNexts = _tmp20_;
	self->priv->writeNexts_length1 = _tmp19_;
	self->priv->_writeNexts_size_ = self->priv->writeNexts_length1;
	self->priv->defaultFirst = -1;
	_tmp21_ = permanentElements;
	_tmp21__length1 = permanentElements_length1;
	if (_tmp21_ != NULL) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp22_ = FALSE;
				_tmp22_ = TRUE;
				while (TRUE) {
					gint _tmp24_ = 0;
					gint _tmp25_ = 0;
					gpointer* _tmp26_ = NULL;
					gint _tmp26__length1 = 0;
					if (!_tmp22_) {
						gint _tmp23_ = 0;
						_tmp23_ = i;
						i = _tmp23_ + 1;
					}
					_tmp22_ = FALSE;
					_tmp24_ = i;
					_tmp25_ = numberOfElements;
					if (!(_tmp24_ < _tmp25_)) {
						break;
					}
					_tmp26_ = permanentElements;
					_tmp26__length1 = permanentElements_length1;
					{
						gpointer* permanentElement_collection = NULL;
						gint permanentElement_collection_length1 = 0;
						gint _permanentElement_collection_size_ = 0;
						gint permanentElement_it = 0;
						permanentElement_collection = _tmp26_;
						permanentElement_collection_length1 = _tmp26__length1;
						for (permanentElement_it = 0; permanentElement_it < _tmp26__length1; permanentElement_it = permanentElement_it + 1) {
							gpointer _tmp27_ = NULL;
							gpointer permanentElement = NULL;
							_tmp27_ = ((permanentElement_collection[permanentElement_it] != NULL) && (elementtype_dup_func != NULL)) ? elementtype_dup_func ((gpointer) permanentElement_collection[permanentElement_it]) : ((gpointer) permanentElement_collection[permanentElement_it]);
							permanentElement = _tmp27_;
							{
								gpointer* _tmp28_ = NULL;
								gint _tmp28__length1 = 0;
								gint _tmp29_ = 0;
								gconstpointer _tmp30_ = NULL;
								gconstpointer _tmp31_ = NULL;
								_tmp28_ = elements;
								_tmp28__length1 = elements_length1;
								_tmp29_ = i;
								_tmp30_ = _tmp28_[_tmp29_];
								_tmp31_ = permanentElement;
								if (_tmp30_ == _tmp31_) {
									gint _tmp32_ = 0;
									_tmp32_ = i;
									update_queue_add_permanent_element (self, _tmp32_);
									_elementtype_destroy_func0 (permanentElement);
									break;
								}
								_elementtype_destroy_func0 (permanentElement);
							}
						}
					}
				}
			}
		}
	}
	_tmp33_ = self->priv->defaultFirst;
	self->priv->readFirst = _tmp33_;
	_tmp34_ = self->priv->defaultFirst;
	self->priv->writeFirst = _tmp34_;
	_tmp35_ = self->priv->defaultFirst;
	self->priv->currentElement = _tmp35_;
	self->priv->readUpdateTime = 0;
	self->priv->writeUpdateTime = 0;
	return self;
}


UpdateQueue* update_queue_new (GType elementtype_type, GBoxedCopyFunc elementtype_dup_func, GDestroyNotify elementtype_destroy_func, gpointer* elements, int elements_length1, gpointer* permanentElements, int permanentElements_length1) {
	return update_queue_construct (TYPE_UPDATE_QUEUE, elementtype_type, elementtype_dup_func, elementtype_destroy_func, elements, elements_length1, permanentElements, permanentElements_length1);
}


static gint* _vala_array_dup99 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


static gint* _vala_array_dup100 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


static gint* _vala_array_dup101 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


static gint* _vala_array_dup102 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


static gint* _vala_array_dup103 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


static gint* _vala_array_dup104 (gint* self, int length) {
	return g_memdup (self, length * sizeof (gint));
}


void update_queue_swap (UpdateQueue* self, gint newTime) {
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint* temporaryArray = NULL;
	gint temporaryArray_length1 = 0;
	gint _temporaryArray_size_ = 0;
	gint* _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	gint* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	gint* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	gint* _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	gint* _tmp6_ = NULL;
	gint _tmp6__length1 = 0;
	gint* _tmp7_ = NULL;
	gint _tmp7__length1 = 0;
	gint* _tmp8_ = NULL;
	gint _tmp8__length1 = 0;
	gint* _tmp9_ = NULL;
	gint _tmp9__length1 = 0;
	gint* _tmp10_ = NULL;
	gint _tmp10__length1 = 0;
	gint* _tmp11_ = NULL;
	gint _tmp11__length1 = 0;
	gint* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	gint* _tmp13_ = NULL;
	gint _tmp13__length1 = 0;
	gint _tmp14_ = 0;
	gint _tmp15_ = 0;
	gint _tmp16_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->writeUpdateTime;
	self->priv->readUpdateTime = _tmp0_;
	_tmp1_ = newTime;
	self->priv->writeUpdateTime = _tmp1_;
	_tmp2_ = self->priv->readTimes;
	_tmp2__length1 = self->priv->readTimes_length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup99 (_tmp2_, _tmp2__length1) : ((gpointer) _tmp2_);
	_tmp3__length1 = _tmp2__length1;
	temporaryArray = (g_free (temporaryArray), NULL);
	temporaryArray = _tmp3_;
	temporaryArray_length1 = _tmp3__length1;
	_temporaryArray_size_ = temporaryArray_length1;
	_tmp4_ = self->priv->writeTimes;
	_tmp4__length1 = self->priv->writeTimes_length1;
	_tmp5_ = (_tmp4_ != NULL) ? _vala_array_dup100 (_tmp4_, _tmp4__length1) : ((gpointer) _tmp4_);
	_tmp5__length1 = _tmp4__length1;
	self->priv->readTimes = (g_free (self->priv->readTimes), NULL);
	self->priv->readTimes = _tmp5_;
	self->priv->readTimes_length1 = _tmp5__length1;
	self->priv->_readTimes_size_ = self->priv->readTimes_length1;
	_tmp6_ = temporaryArray;
	_tmp6__length1 = temporaryArray_length1;
	_tmp7_ = (_tmp6_ != NULL) ? _vala_array_dup101 (_tmp6_, _tmp6__length1) : ((gpointer) _tmp6_);
	_tmp7__length1 = _tmp6__length1;
	self->priv->writeTimes = (g_free (self->priv->writeTimes), NULL);
	self->priv->writeTimes = _tmp7_;
	self->priv->writeTimes_length1 = _tmp7__length1;
	self->priv->_writeTimes_size_ = self->priv->writeTimes_length1;
	_tmp8_ = self->priv->readNexts;
	_tmp8__length1 = self->priv->readNexts_length1;
	_tmp9_ = (_tmp8_ != NULL) ? _vala_array_dup102 (_tmp8_, _tmp8__length1) : ((gpointer) _tmp8_);
	_tmp9__length1 = _tmp8__length1;
	temporaryArray = (g_free (temporaryArray), NULL);
	temporaryArray = _tmp9_;
	temporaryArray_length1 = _tmp9__length1;
	_temporaryArray_size_ = temporaryArray_length1;
	_tmp10_ = self->priv->writeNexts;
	_tmp10__length1 = self->priv->writeNexts_length1;
	_tmp11_ = (_tmp10_ != NULL) ? _vala_array_dup103 (_tmp10_, _tmp10__length1) : ((gpointer) _tmp10_);
	_tmp11__length1 = _tmp10__length1;
	self->priv->readNexts = (g_free (self->priv->readNexts), NULL);
	self->priv->readNexts = _tmp11_;
	self->priv->readNexts_length1 = _tmp11__length1;
	self->priv->_readNexts_size_ = self->priv->readNexts_length1;
	_tmp12_ = temporaryArray;
	_tmp12__length1 = temporaryArray_length1;
	_tmp13_ = (_tmp12_ != NULL) ? _vala_array_dup104 (_tmp12_, _tmp12__length1) : ((gpointer) _tmp12_);
	_tmp13__length1 = _tmp12__length1;
	self->priv->writeNexts = (g_free (self->priv->writeNexts), NULL);
	self->priv->writeNexts = _tmp13_;
	self->priv->writeNexts_length1 = _tmp13__length1;
	self->priv->_writeNexts_size_ = self->priv->writeNexts_length1;
	_tmp14_ = self->priv->writeFirst;
	self->priv->readFirst = _tmp14_;
	_tmp15_ = self->priv->defaultFirst;
	self->priv->writeFirst = _tmp15_;
	_tmp16_ = self->priv->readFirst;
	self->priv->currentElement = _tmp16_;
	temporaryArray = (g_free (temporaryArray), NULL);
}


void update_queue_full_update (UpdateQueue* self) {
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				gint _tmp2_ = 0;
				gpointer* _tmp3_ = NULL;
				gint _tmp3__length1 = 0;
				gint _tmp4_ = 0;
				if (!_tmp0_) {
					gint _tmp1_ = 0;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = i;
				_tmp3_ = self->elements;
				_tmp3__length1 = self->elements_length1;
				if (!(_tmp2_ < _tmp3__length1)) {
					break;
				}
				_tmp4_ = i;
				update_queue_add_element (self, _tmp4_);
			}
		}
	}
}


void update_queue_add_element (UpdateQueue* self, gint elementNumber) {
	gint* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->writeTimes;
	_tmp0__length1 = self->priv->writeTimes_length1;
	_tmp1_ = elementNumber;
	_tmp2_ = _tmp0_[_tmp1_];
	_tmp3_ = self->priv->writeUpdateTime;
	if (_tmp2_ < _tmp3_) {
		gint* _tmp4_ = NULL;
		gint _tmp4__length1 = 0;
		gint _tmp5_ = 0;
		gint _tmp6_ = 0;
		gint _tmp7_ = 0;
		gint* _tmp8_ = NULL;
		gint _tmp8__length1 = 0;
		gint _tmp9_ = 0;
		gint _tmp10_ = 0;
		gint _tmp11_ = 0;
		gint _tmp12_ = 0;
		_tmp4_ = self->priv->writeTimes;
		_tmp4__length1 = self->priv->writeTimes_length1;
		_tmp5_ = elementNumber;
		_tmp6_ = self->priv->writeUpdateTime;
		_tmp4_[_tmp5_] = _tmp6_;
		_tmp7_ = _tmp4_[_tmp5_];
		_tmp8_ = self->priv->writeNexts;
		_tmp8__length1 = self->priv->writeNexts_length1;
		_tmp9_ = elementNumber;
		_tmp10_ = self->priv->writeFirst;
		_tmp8_[_tmp9_] = _tmp10_;
		_tmp11_ = _tmp8_[_tmp9_];
		_tmp12_ = elementNumber;
		self->priv->writeFirst = _tmp12_;
	}
}


void update_queue_add_permanent_element (UpdateQueue* self, gint elementNumber) {
	gint* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gint* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	gint _tmp5_ = 0;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
	gint* _tmp8_ = NULL;
	gint _tmp8__length1 = 0;
	gint _tmp9_ = 0;
	gint _tmp10_ = 0;
	gint _tmp11_ = 0;
	gint* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	gint _tmp13_ = 0;
	gint _tmp14_ = 0;
	gint _tmp15_ = 0;
	gint _tmp16_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->writeTimes;
	_tmp0__length1 = self->priv->writeTimes_length1;
	_tmp1_ = elementNumber;
	_tmp2_ = G_MAXINT;
	_tmp0_[_tmp1_] = _tmp2_;
	_tmp3_ = _tmp0_[_tmp1_];
	_tmp4_ = self->priv->readTimes;
	_tmp4__length1 = self->priv->readTimes_length1;
	_tmp5_ = elementNumber;
	_tmp6_ = G_MAXINT;
	_tmp4_[_tmp5_] = _tmp6_;
	_tmp7_ = _tmp4_[_tmp5_];
	_tmp8_ = self->priv->writeNexts;
	_tmp8__length1 = self->priv->writeNexts_length1;
	_tmp9_ = elementNumber;
	_tmp10_ = self->priv->defaultFirst;
	_tmp8_[_tmp9_] = _tmp10_;
	_tmp11_ = _tmp8_[_tmp9_];
	_tmp12_ = self->priv->readNexts;
	_tmp12__length1 = self->priv->readNexts_length1;
	_tmp13_ = elementNumber;
	_tmp14_ = self->priv->defaultFirst;
	_tmp12_[_tmp13_] = _tmp14_;
	_tmp15_ = _tmp12_[_tmp13_];
	_tmp16_ = elementNumber;
	self->priv->defaultFirst = _tmp16_;
}


gpointer update_queue_get_next_element (UpdateQueue* self) {
	gpointer result = NULL;
	gint _tmp0_ = 0;
	gpointer element = NULL;
	gpointer* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gint _tmp2_ = 0;
	gconstpointer _tmp3_ = NULL;
	gpointer _tmp4_ = NULL;
	gint* _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->currentElement;
	if (_tmp0_ == (-1)) {
		result = NULL;
		return result;
	}
	_tmp1_ = self->elements;
	_tmp1__length1 = self->elements_length1;
	_tmp2_ = self->priv->currentElement;
	_tmp3_ = _tmp1_[_tmp2_];
	_tmp4_ = ((_tmp3_ != NULL) && (self->priv->elementtype_dup_func != NULL)) ? self->priv->elementtype_dup_func ((gpointer) _tmp3_) : ((gpointer) _tmp3_);
	element = _tmp4_;
	_tmp5_ = self->priv->readNexts;
	_tmp5__length1 = self->priv->readNexts_length1;
	_tmp6_ = self->priv->currentElement;
	_tmp7_ = _tmp5_[_tmp6_];
	self->priv->currentElement = _tmp7_;
	result = element;
	return result;
}


static void value_update_queue_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_update_queue_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		update_queue_unref (value->data[0].v_pointer);
	}
}


static void value_update_queue_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = update_queue_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_update_queue_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_update_queue_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		UpdateQueue* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = update_queue_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_update_queue_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	UpdateQueue** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = update_queue_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_update_queue (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecUpdateQueue* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_UPDATE_QUEUE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_update_queue (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_UPDATE_QUEUE), NULL);
	return value->data[0].v_pointer;
}


void value_set_update_queue (GValue* value, gpointer v_object) {
	UpdateQueue* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_UPDATE_QUEUE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_UPDATE_QUEUE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		update_queue_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		update_queue_unref (old);
	}
}


void value_take_update_queue (GValue* value, gpointer v_object) {
	UpdateQueue* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_UPDATE_QUEUE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_UPDATE_QUEUE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		update_queue_unref (old);
	}
}


static void update_queue_class_init (UpdateQueueClass * klass) {
	update_queue_parent_class = g_type_class_peek_parent (klass);
	UPDATE_QUEUE_CLASS (klass)->finalize = update_queue_finalize;
	g_type_class_add_private (klass, sizeof (UpdateQueuePrivate));
}


static void update_queue_instance_init (UpdateQueue * self) {
	self->priv = UPDATE_QUEUE_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void update_queue_finalize (UpdateQueue* obj) {
	UpdateQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UPDATE_QUEUE, UpdateQueue);
	self->elements = (_vala_array_free (self->elements, self->elements_length1, (GDestroyNotify) self->priv->elementtype_destroy_func), NULL);
	self->priv->readTimes = (g_free (self->priv->readTimes), NULL);
	self->priv->writeTimes = (g_free (self->priv->writeTimes), NULL);
	self->priv->readNexts = (g_free (self->priv->readNexts), NULL);
	self->priv->writeNexts = (g_free (self->priv->writeNexts), NULL);
}


GType update_queue_get_type (void) {
	static volatile gsize update_queue_type_id__volatile = 0;
	if (g_once_init_enter (&update_queue_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_update_queue_init, value_update_queue_free_value, value_update_queue_copy_value, value_update_queue_peek_pointer, "p", value_update_queue_collect_value, "p", value_update_queue_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (UpdateQueueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) update_queue_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UpdateQueue), 0, (GInstanceInitFunc) update_queue_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType update_queue_type_id;
		update_queue_type_id = g_type_register_fundamental (g_type_fundamental_next (), "UpdateQueue", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&update_queue_type_id__volatile, update_queue_type_id);
	}
	return update_queue_type_id__volatile;
}


gpointer update_queue_ref (gpointer instance) {
	UpdateQueue* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void update_queue_unref (gpointer instance) {
	UpdateQueue* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		UPDATE_QUEUE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



