/* trellis-node.c generated by valac 0.56.19, the Vala compiler
 * generated from trellis-node.vala, do not modify */

/*
 * Copyright (C) 2012-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2012-2014 Red Hat, Inc.
 *
 * 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/>.
 */

#include "libkkc/libkkc.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _kkc_trellis_node_unref0(var) ((var == NULL) ? NULL : (var = (kkc_trellis_node_unref (var), NULL)))
typedef struct _KkcParamSpecTrellisNode KkcParamSpecTrellisNode;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _KkcParamSpecTrellisNode {
	GParamSpec parent_instance;
};

struct _KkcUnigramTrellisNodePrivate {
	KkcLanguageModelEntry _entry;
	guint _endpos;
	KkcLanguageModelEntry* _entries;
	gint _entries_length1;
	gint __entries_size_;
};

struct _KkcBigramTrellisNodePrivate {
	KkcUnigramTrellisNode* _left_node;
	KkcUnigramTrellisNode* _right_node;
	gchar* _input;
	gchar* _output;
	guint _endpos;
	KkcLanguageModelEntry* _entries;
	gint _entries_length1;
	gint __entries_size_;
};

static gpointer kkc_trellis_node_parent_class = NULL;
static gint KkcUnigramTrellisNode_private_offset;
static gpointer kkc_unigram_trellis_node_parent_class = NULL;
static gint KkcBigramTrellisNode_private_offset;
static gpointer kkc_bigram_trellis_node_parent_class = NULL;

static gchar* kkc_trellis_node_real_to_string (KkcTrellisNode* self);
static void kkc_trellis_node_finalize (KkcTrellisNode * obj);
static GType kkc_trellis_node_get_type_once (void);
static void _vala_KkcLanguageModelEntry_array_free (KkcLanguageModelEntry * array,
                                             gssize array_length);
static gchar* kkc_unigram_trellis_node_real_to_string (KkcTrellisNode* base);
static void kkc_unigram_trellis_node_finalize (KkcTrellisNode * obj);
static GType kkc_unigram_trellis_node_get_type_once (void);
static gchar* kkc_bigram_trellis_node_real_to_string (KkcTrellisNode* base);
static void kkc_bigram_trellis_node_finalize (KkcTrellisNode * obj);
static GType kkc_bigram_trellis_node_get_type_once (void);

static gchar*
kkc_trellis_node_real_to_string (KkcTrellisNode* self)
{
	g_critical ("Type `%s' does not implement abstract method `kkc_trellis_node_to_string'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
kkc_trellis_node_to_string (KkcTrellisNode* self)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->to_string) {
		return _klass_->to_string (self);
	}
	return NULL;
}

KkcTrellisNode*
kkc_trellis_node_construct (GType object_type)
{
	KkcTrellisNode* self = NULL;
	self = (KkcTrellisNode*) g_type_create_instance (object_type);
	return self;
}

guint
kkc_trellis_node_get_endpos (KkcTrellisNode* self)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, 0U);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->get_endpos) {
		return _klass_->get_endpos (self);
	}
	return 0U;
}

guint
kkc_trellis_node_get_length (KkcTrellisNode* self)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, 0U);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->get_length) {
		return _klass_->get_length (self);
	}
	return 0U;
}

const gchar*
kkc_trellis_node_get_input (KkcTrellisNode* self)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->get_input) {
		return _klass_->get_input (self);
	}
	return NULL;
}

const gchar*
kkc_trellis_node_get_output (KkcTrellisNode* self)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->get_output) {
		return _klass_->get_output (self);
	}
	return NULL;
}

KkcLanguageModelEntry*
kkc_trellis_node_get_entries (KkcTrellisNode* self,
                              gint* result_length1)
{
	KkcTrellisNodeClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_TRELLIS_NODE_GET_CLASS (self);
	if (_klass_->get_entries) {
		return _klass_->get_entries (self, result_length1);
	}
	return NULL;
}

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

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

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

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

static gchar*
kkc_value_trellis_node_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		KkcTrellisNode * 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 = kkc_trellis_node_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
kkc_value_trellis_node_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	KkcTrellisNode ** 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 = kkc_trellis_node_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
kkc_param_spec_trellis_node (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	KkcParamSpecTrellisNode* spec;
	g_return_val_if_fail (g_type_is_a (object_type, KKC_TYPE_TRELLIS_NODE), 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
kkc_value_get_trellis_node (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_TYPE_TRELLIS_NODE), NULL);
	return value->data[0].v_pointer;
}

void
kkc_value_set_trellis_node (GValue* value,
                            gpointer v_object)
{
	KkcTrellisNode * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_TYPE_TRELLIS_NODE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KKC_TYPE_TRELLIS_NODE));
		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;
		kkc_trellis_node_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		kkc_trellis_node_unref (old);
	}
}

void
kkc_value_take_trellis_node (GValue* value,
                             gpointer v_object)
{
	KkcTrellisNode * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_TYPE_TRELLIS_NODE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KKC_TYPE_TRELLIS_NODE));
		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) {
		kkc_trellis_node_unref (old);
	}
}

static void
kkc_trellis_node_class_init (KkcTrellisNodeClass * klass,
                             gpointer klass_data)
{
	kkc_trellis_node_parent_class = g_type_class_peek_parent (klass);
	((KkcTrellisNodeClass *) klass)->finalize = kkc_trellis_node_finalize;
	((KkcTrellisNodeClass *) klass)->to_string = (gchar* (*) (KkcTrellisNode*)) kkc_trellis_node_real_to_string;
}

static void
kkc_trellis_node_instance_init (KkcTrellisNode * self,
                                gpointer klass)
{
	self->ref_count = 1;
}

static void
kkc_trellis_node_finalize (KkcTrellisNode * obj)
{
	KkcTrellisNode * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_TRELLIS_NODE, KkcTrellisNode);
	g_signal_handlers_destroy (self);
	_kkc_trellis_node_unref0 (self->previous);
}

static GType
kkc_trellis_node_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { kkc_value_trellis_node_init, kkc_value_trellis_node_free_value, kkc_value_trellis_node_copy_value, kkc_value_trellis_node_peek_pointer, "p", kkc_value_trellis_node_collect_value, "p", kkc_value_trellis_node_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (KkcTrellisNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_trellis_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcTrellisNode), 0, (GInstanceInitFunc) kkc_trellis_node_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 kkc_trellis_node_type_id;
	kkc_trellis_node_type_id = g_type_register_fundamental (g_type_fundamental_next (), "KkcTrellisNode", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_ABSTRACT);
	return kkc_trellis_node_type_id;
}

GType
kkc_trellis_node_get_type (void)
{
	static volatile gsize kkc_trellis_node_type_id__once = 0;
	if (g_once_init_enter (&kkc_trellis_node_type_id__once)) {
		GType kkc_trellis_node_type_id;
		kkc_trellis_node_type_id = kkc_trellis_node_get_type_once ();
		g_once_init_leave (&kkc_trellis_node_type_id__once, kkc_trellis_node_type_id);
	}
	return kkc_trellis_node_type_id__once;
}

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

void
kkc_trellis_node_unref (gpointer instance)
{
	KkcTrellisNode * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		KKC_TRELLIS_NODE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
kkc_unigram_trellis_node_get_instance_private (KkcUnigramTrellisNode* self)
{
	return G_STRUCT_MEMBER_P (self, KkcUnigramTrellisNode_private_offset);
}

static void
_vala_KkcLanguageModelEntry_array_free (KkcLanguageModelEntry * array,
                                        gssize array_length)
{
	if (array != NULL) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			kkc_language_model_entry_destroy (&array[i]);
		}
	}
	g_free (array);
}

KkcUnigramTrellisNode*
kkc_unigram_trellis_node_construct (GType object_type,
                                    KkcLanguageModelEntry* entry,
                                    guint endpos)
{
	KkcUnigramTrellisNode* self = NULL;
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	KkcLanguageModelEntry _tmp2_ = {0};
	KkcLanguageModelEntry _tmp3_;
	KkcLanguageModelEntry _tmp4_;
	KkcLanguageModelEntry _tmp5_ = {0};
	KkcLanguageModelEntry* _tmp6_;
	g_return_val_if_fail (entry != NULL, NULL);
	self = (KkcUnigramTrellisNode*) kkc_trellis_node_construct (object_type);
	_tmp0_ = *entry;
	_tmp1_ = _tmp0_;
	kkc_language_model_entry_copy (&_tmp1_, &_tmp2_);
	kkc_language_model_entry_destroy (&self->priv->_entry);
	self->priv->_entry = _tmp2_;
	self->priv->_endpos = endpos;
	_tmp3_ = self->priv->_entry;
	_tmp4_ = _tmp3_;
	kkc_language_model_entry_copy (&_tmp4_, &_tmp5_);
	_tmp6_ = g_new0 (KkcLanguageModelEntry, 1);
	_tmp6_[0] = _tmp5_;
	self->priv->_entries = (_vala_KkcLanguageModelEntry_array_free (self->priv->_entries, self->priv->_entries_length1), NULL);
	self->priv->_entries = _tmp6_;
	self->priv->_entries_length1 = 1;
	self->priv->__entries_size_ = self->priv->_entries_length1;
	return self;
}

KkcUnigramTrellisNode*
kkc_unigram_trellis_node_new (KkcLanguageModelEntry* entry,
                              guint endpos)
{
	return kkc_unigram_trellis_node_construct (KKC_TYPE_UNIGRAM_TRELLIS_NODE, entry, endpos);
}

static gchar*
kkc_unigram_trellis_node_real_to_string (KkcTrellisNode* base)
{
	KkcUnigramTrellisNode * self;
	KkcLanguageModelEntry _tmp0_;
	const gchar* _tmp1_;
	KkcLanguageModelEntry _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	self = (KkcUnigramTrellisNode*) base;
	_tmp0_ = self->priv->_entry;
	_tmp1_ = _tmp0_.input;
	_tmp2_ = self->priv->_entry;
	_tmp3_ = _tmp2_.output;
	_tmp4_ = g_strdup_printf ("<%s/%s>", _tmp1_, _tmp3_);
	result = _tmp4_;
	return result;
}

void
kkc_unigram_trellis_node_get_entry (KkcUnigramTrellisNode* self,
                                    KkcLanguageModelEntry * result)
{
	KkcLanguageModelEntry _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_entry;
	*result = _tmp0_;
	return;
}

static const gchar*
kkc_unigram_trellis_node_real_get_input (KkcTrellisNode* base)
{
	const gchar* result;
	KkcUnigramTrellisNode* self;
	KkcLanguageModelEntry _tmp0_;
	const gchar* _tmp1_;
	self = (KkcUnigramTrellisNode*) base;
	_tmp0_ = self->priv->_entry;
	_tmp1_ = _tmp0_.input;
	result = _tmp1_;
	return result;
}

static const gchar*
kkc_unigram_trellis_node_real_get_output (KkcTrellisNode* base)
{
	const gchar* result;
	KkcUnigramTrellisNode* self;
	KkcLanguageModelEntry _tmp0_;
	const gchar* _tmp1_;
	self = (KkcUnigramTrellisNode*) base;
	_tmp0_ = self->priv->_entry;
	_tmp1_ = _tmp0_.output;
	result = _tmp1_;
	return result;
}

static guint
kkc_unigram_trellis_node_real_get_endpos (KkcTrellisNode* base)
{
	guint result;
	KkcUnigramTrellisNode* self;
	self = (KkcUnigramTrellisNode*) base;
	result = self->priv->_endpos;
	return result;
}

static guint
kkc_unigram_trellis_node_real_get_length (KkcTrellisNode* base)
{
	guint result;
	KkcUnigramTrellisNode* self;
	KkcLanguageModelEntry _tmp0_;
	const gchar* _tmp1_;
	self = (KkcUnigramTrellisNode*) base;
	_tmp0_ = self->priv->_entry;
	_tmp1_ = _tmp0_.input;
	result = (guint) g_utf8_strlen (_tmp1_, (gssize) -1);
	return result;
}

static KkcLanguageModelEntry*
kkc_unigram_trellis_node_real_get_entries (KkcTrellisNode* base,
                                           gint* result_length1)
{
	KkcLanguageModelEntry* result;
	KkcUnigramTrellisNode* self;
	KkcLanguageModelEntry* _tmp0_;
	gint _tmp0__length1;
	KkcLanguageModelEntry* _tmp1_;
	gint _tmp1__length1;
	self = (KkcUnigramTrellisNode*) base;
	_tmp0_ = self->priv->_entries;
	_tmp0__length1 = self->priv->_entries_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
kkc_unigram_trellis_node_class_init (KkcUnigramTrellisNodeClass * klass,
                                     gpointer klass_data)
{
	kkc_unigram_trellis_node_parent_class = g_type_class_peek_parent (klass);
	((KkcTrellisNodeClass *) klass)->finalize = kkc_unigram_trellis_node_finalize;
	g_type_class_adjust_private_offset (klass, &KkcUnigramTrellisNode_private_offset);
	((KkcTrellisNodeClass *) klass)->to_string = (gchar* (*) (KkcTrellisNode*)) kkc_unigram_trellis_node_real_to_string;
	KKC_TRELLIS_NODE_CLASS (klass)->get_input = (const gchar* (*) (KkcTrellisNode*)) kkc_unigram_trellis_node_real_get_input;
	KKC_TRELLIS_NODE_CLASS (klass)->get_output = (const gchar* (*) (KkcTrellisNode*)) kkc_unigram_trellis_node_real_get_output;
	KKC_TRELLIS_NODE_CLASS (klass)->get_endpos = (guint (*) (KkcTrellisNode*)) kkc_unigram_trellis_node_real_get_endpos;
	KKC_TRELLIS_NODE_CLASS (klass)->get_length = (guint (*) (KkcTrellisNode*)) kkc_unigram_trellis_node_real_get_length;
	KKC_TRELLIS_NODE_CLASS (klass)->get_entries = (KkcLanguageModelEntry* (*) (KkcTrellisNode*, gint*)) kkc_unigram_trellis_node_real_get_entries;
}

static void
kkc_unigram_trellis_node_instance_init (KkcUnigramTrellisNode * self,
                                        gpointer klass)
{
	self->priv = kkc_unigram_trellis_node_get_instance_private (self);
}

static void
kkc_unigram_trellis_node_finalize (KkcTrellisNode * obj)
{
	KkcUnigramTrellisNode * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_UNIGRAM_TRELLIS_NODE, KkcUnigramTrellisNode);
	kkc_language_model_entry_destroy (&self->priv->_entry);
	self->priv->_entries = (_vala_KkcLanguageModelEntry_array_free (self->priv->_entries, self->priv->_entries_length1), NULL);
	KKC_TRELLIS_NODE_CLASS (kkc_unigram_trellis_node_parent_class)->finalize (obj);
}

static GType
kkc_unigram_trellis_node_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcUnigramTrellisNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_unigram_trellis_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcUnigramTrellisNode), 0, (GInstanceInitFunc) kkc_unigram_trellis_node_instance_init, NULL };
	GType kkc_unigram_trellis_node_type_id;
	kkc_unigram_trellis_node_type_id = g_type_register_static (KKC_TYPE_TRELLIS_NODE, "KkcUnigramTrellisNode", &g_define_type_info, 0);
	KkcUnigramTrellisNode_private_offset = g_type_add_instance_private (kkc_unigram_trellis_node_type_id, sizeof (KkcUnigramTrellisNodePrivate));
	return kkc_unigram_trellis_node_type_id;
}

GType
kkc_unigram_trellis_node_get_type (void)
{
	static volatile gsize kkc_unigram_trellis_node_type_id__once = 0;
	if (g_once_init_enter (&kkc_unigram_trellis_node_type_id__once)) {
		GType kkc_unigram_trellis_node_type_id;
		kkc_unigram_trellis_node_type_id = kkc_unigram_trellis_node_get_type_once ();
		g_once_init_leave (&kkc_unigram_trellis_node_type_id__once, kkc_unigram_trellis_node_type_id);
	}
	return kkc_unigram_trellis_node_type_id__once;
}

static inline gpointer
kkc_bigram_trellis_node_get_instance_private (KkcBigramTrellisNode* self)
{
	return G_STRUCT_MEMBER_P (self, KkcBigramTrellisNode_private_offset);
}

static gpointer
_kkc_trellis_node_ref0 (gpointer self)
{
	return self ? kkc_trellis_node_ref (self) : NULL;
}

KkcBigramTrellisNode*
kkc_bigram_trellis_node_construct (GType object_type,
                                   KkcUnigramTrellisNode* left_node,
                                   KkcUnigramTrellisNode* right_node,
                                   guint endpos)
{
	KkcBigramTrellisNode* self = NULL;
	KkcUnigramTrellisNode* _tmp0_;
	KkcUnigramTrellisNode* _tmp1_;
	KkcUnigramTrellisNode* _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	KkcLanguageModelEntry _tmp33_ = {0};
	KkcLanguageModelEntry _tmp34_;
	KkcLanguageModelEntry _tmp35_;
	KkcLanguageModelEntry _tmp36_ = {0};
	KkcLanguageModelEntry _tmp37_ = {0};
	KkcLanguageModelEntry _tmp38_;
	KkcLanguageModelEntry _tmp39_;
	KkcLanguageModelEntry _tmp40_ = {0};
	KkcLanguageModelEntry* _tmp41_;
	g_return_val_if_fail (left_node != NULL, NULL);
	g_return_val_if_fail (right_node != NULL, NULL);
	self = (KkcBigramTrellisNode*) kkc_trellis_node_construct (object_type);
	_tmp0_ = _kkc_trellis_node_ref0 (left_node);
	_kkc_trellis_node_unref0 (self->priv->_left_node);
	self->priv->_left_node = _tmp0_;
	_tmp1_ = _kkc_trellis_node_ref0 (right_node);
	_kkc_trellis_node_unref0 (self->priv->_right_node);
	self->priv->_right_node = _tmp1_;
	self->priv->_endpos = endpos;
	_tmp2_ = self->priv->_right_node;
	_tmp3_ = kkc_trellis_node_get_endpos ((KkcTrellisNode*) _tmp2_);
	_tmp4_ = _tmp3_;
	if (self->priv->_endpos < _tmp4_) {
		KkcUnigramTrellisNode* _tmp5_;
		KkcLanguageModelEntry _tmp6_ = {0};
		KkcLanguageModelEntry _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		KkcUnigramTrellisNode* _tmp10_;
		KkcLanguageModelEntry _tmp11_ = {0};
		KkcLanguageModelEntry _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		_tmp5_ = self->priv->_left_node;
		kkc_unigram_trellis_node_get_entry (_tmp5_, &_tmp6_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_.input;
		_tmp9_ = g_strdup (_tmp8_);
		_g_free0 (self->priv->_input);
		self->priv->_input = _tmp9_;
		_tmp10_ = self->priv->_left_node;
		kkc_unigram_trellis_node_get_entry (_tmp10_, &_tmp11_);
		_tmp12_ = _tmp11_;
		_tmp13_ = _tmp12_.output;
		_tmp14_ = g_strdup (_tmp13_);
		_g_free0 (self->priv->_output);
		self->priv->_output = _tmp14_;
	} else {
		KkcUnigramTrellisNode* _tmp15_;
		KkcLanguageModelEntry _tmp16_ = {0};
		KkcLanguageModelEntry _tmp17_;
		const gchar* _tmp18_;
		KkcUnigramTrellisNode* _tmp19_;
		KkcLanguageModelEntry _tmp20_ = {0};
		KkcLanguageModelEntry _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		KkcUnigramTrellisNode* _tmp24_;
		KkcLanguageModelEntry _tmp25_ = {0};
		KkcLanguageModelEntry _tmp26_;
		const gchar* _tmp27_;
		KkcUnigramTrellisNode* _tmp28_;
		KkcLanguageModelEntry _tmp29_ = {0};
		KkcLanguageModelEntry _tmp30_;
		const gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp15_ = self->priv->_left_node;
		kkc_unigram_trellis_node_get_entry (_tmp15_, &_tmp16_);
		_tmp17_ = _tmp16_;
		_tmp18_ = _tmp17_.input;
		_tmp19_ = self->priv->_right_node;
		kkc_unigram_trellis_node_get_entry (_tmp19_, &_tmp20_);
		_tmp21_ = _tmp20_;
		_tmp22_ = _tmp21_.input;
		_tmp23_ = g_strconcat (_tmp18_, _tmp22_, NULL);
		_g_free0 (self->priv->_input);
		self->priv->_input = _tmp23_;
		_tmp24_ = self->priv->_left_node;
		kkc_unigram_trellis_node_get_entry (_tmp24_, &_tmp25_);
		_tmp26_ = _tmp25_;
		_tmp27_ = _tmp26_.output;
		_tmp28_ = self->priv->_right_node;
		kkc_unigram_trellis_node_get_entry (_tmp28_, &_tmp29_);
		_tmp30_ = _tmp29_;
		_tmp31_ = _tmp30_.output;
		_tmp32_ = g_strconcat (_tmp27_, _tmp31_, NULL);
		_g_free0 (self->priv->_output);
		self->priv->_output = _tmp32_;
	}
	kkc_unigram_trellis_node_get_entry (left_node, &_tmp33_);
	_tmp34_ = _tmp33_;
	_tmp35_ = _tmp34_;
	kkc_language_model_entry_copy (&_tmp35_, &_tmp36_);
	kkc_unigram_trellis_node_get_entry (right_node, &_tmp37_);
	_tmp38_ = _tmp37_;
	_tmp39_ = _tmp38_;
	kkc_language_model_entry_copy (&_tmp39_, &_tmp40_);
	_tmp41_ = g_new0 (KkcLanguageModelEntry, 2);
	_tmp41_[0] = _tmp36_;
	_tmp41_[1] = _tmp40_;
	self->priv->_entries = (_vala_KkcLanguageModelEntry_array_free (self->priv->_entries, self->priv->_entries_length1), NULL);
	self->priv->_entries = _tmp41_;
	self->priv->_entries_length1 = 2;
	self->priv->__entries_size_ = self->priv->_entries_length1;
	return self;
}

KkcBigramTrellisNode*
kkc_bigram_trellis_node_new (KkcUnigramTrellisNode* left_node,
                             KkcUnigramTrellisNode* right_node,
                             guint endpos)
{
	return kkc_bigram_trellis_node_construct (KKC_TYPE_BIGRAM_TRELLIS_NODE, left_node, right_node, endpos);
}

static gchar*
kkc_bigram_trellis_node_real_to_string (KkcTrellisNode* base)
{
	KkcBigramTrellisNode * self;
	KkcUnigramTrellisNode* _tmp0_;
	KkcLanguageModelEntry _tmp1_ = {0};
	KkcLanguageModelEntry _tmp2_;
	const gchar* _tmp3_;
	KkcUnigramTrellisNode* _tmp4_;
	KkcLanguageModelEntry _tmp5_ = {0};
	KkcLanguageModelEntry _tmp6_;
	const gchar* _tmp7_;
	KkcUnigramTrellisNode* _tmp8_;
	KkcLanguageModelEntry _tmp9_ = {0};
	KkcLanguageModelEntry _tmp10_;
	const gchar* _tmp11_;
	KkcUnigramTrellisNode* _tmp12_;
	KkcLanguageModelEntry _tmp13_ = {0};
	KkcLanguageModelEntry _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* result;
	self = (KkcBigramTrellisNode*) base;
	_tmp0_ = self->priv->_left_node;
	kkc_unigram_trellis_node_get_entry (_tmp0_, &_tmp1_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_.input;
	_tmp4_ = self->priv->_left_node;
	kkc_unigram_trellis_node_get_entry (_tmp4_, &_tmp5_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_.output;
	_tmp8_ = self->priv->_right_node;
	kkc_unigram_trellis_node_get_entry (_tmp8_, &_tmp9_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_.input;
	_tmp12_ = self->priv->_right_node;
	kkc_unigram_trellis_node_get_entry (_tmp12_, &_tmp13_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_.output;
	_tmp16_ = g_strdup_printf ("<%s/%s><%s/%s>", _tmp3_, _tmp7_, _tmp11_, _tmp15_);
	result = _tmp16_;
	return result;
}

KkcUnigramTrellisNode*
kkc_bigram_trellis_node_get_left_node (KkcBigramTrellisNode* self)
{
	KkcUnigramTrellisNode* result;
	KkcUnigramTrellisNode* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_left_node;
	result = _tmp0_;
	return result;
}

KkcUnigramTrellisNode*
kkc_bigram_trellis_node_get_right_node (KkcBigramTrellisNode* self)
{
	KkcUnigramTrellisNode* result;
	KkcUnigramTrellisNode* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_right_node;
	result = _tmp0_;
	return result;
}

static const gchar*
kkc_bigram_trellis_node_real_get_input (KkcTrellisNode* base)
{
	const gchar* result;
	KkcBigramTrellisNode* self;
	const gchar* _tmp0_;
	self = (KkcBigramTrellisNode*) base;
	_tmp0_ = self->priv->_input;
	result = _tmp0_;
	return result;
}

static const gchar*
kkc_bigram_trellis_node_real_get_output (KkcTrellisNode* base)
{
	const gchar* result;
	KkcBigramTrellisNode* self;
	const gchar* _tmp0_;
	self = (KkcBigramTrellisNode*) base;
	_tmp0_ = self->priv->_output;
	result = _tmp0_;
	return result;
}

static guint
kkc_bigram_trellis_node_real_get_endpos (KkcTrellisNode* base)
{
	guint result;
	KkcBigramTrellisNode* self;
	self = (KkcBigramTrellisNode*) base;
	result = self->priv->_endpos;
	return result;
}

static guint
kkc_bigram_trellis_node_real_get_length (KkcTrellisNode* base)
{
	guint result;
	KkcBigramTrellisNode* self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	self = (KkcBigramTrellisNode*) base;
	_tmp0_ = kkc_trellis_node_get_input ((KkcTrellisNode*) self);
	_tmp1_ = _tmp0_;
	result = (guint) g_utf8_strlen (_tmp1_, (gssize) -1);
	return result;
}

static KkcLanguageModelEntry*
kkc_bigram_trellis_node_real_get_entries (KkcTrellisNode* base,
                                          gint* result_length1)
{
	KkcLanguageModelEntry* result;
	KkcBigramTrellisNode* self;
	KkcLanguageModelEntry* _tmp0_;
	gint _tmp0__length1;
	KkcLanguageModelEntry* _tmp1_;
	gint _tmp1__length1;
	self = (KkcBigramTrellisNode*) base;
	_tmp0_ = self->priv->_entries;
	_tmp0__length1 = self->priv->_entries_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
kkc_bigram_trellis_node_class_init (KkcBigramTrellisNodeClass * klass,
                                    gpointer klass_data)
{
	kkc_bigram_trellis_node_parent_class = g_type_class_peek_parent (klass);
	((KkcTrellisNodeClass *) klass)->finalize = kkc_bigram_trellis_node_finalize;
	g_type_class_adjust_private_offset (klass, &KkcBigramTrellisNode_private_offset);
	((KkcTrellisNodeClass *) klass)->to_string = (gchar* (*) (KkcTrellisNode*)) kkc_bigram_trellis_node_real_to_string;
	KKC_TRELLIS_NODE_CLASS (klass)->get_input = (const gchar* (*) (KkcTrellisNode*)) kkc_bigram_trellis_node_real_get_input;
	KKC_TRELLIS_NODE_CLASS (klass)->get_output = (const gchar* (*) (KkcTrellisNode*)) kkc_bigram_trellis_node_real_get_output;
	KKC_TRELLIS_NODE_CLASS (klass)->get_endpos = (guint (*) (KkcTrellisNode*)) kkc_bigram_trellis_node_real_get_endpos;
	KKC_TRELLIS_NODE_CLASS (klass)->get_length = (guint (*) (KkcTrellisNode*)) kkc_bigram_trellis_node_real_get_length;
	KKC_TRELLIS_NODE_CLASS (klass)->get_entries = (KkcLanguageModelEntry* (*) (KkcTrellisNode*, gint*)) kkc_bigram_trellis_node_real_get_entries;
}

static void
kkc_bigram_trellis_node_instance_init (KkcBigramTrellisNode * self,
                                       gpointer klass)
{
	self->priv = kkc_bigram_trellis_node_get_instance_private (self);
}

static void
kkc_bigram_trellis_node_finalize (KkcTrellisNode * obj)
{
	KkcBigramTrellisNode * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_BIGRAM_TRELLIS_NODE, KkcBigramTrellisNode);
	_kkc_trellis_node_unref0 (self->priv->_left_node);
	_kkc_trellis_node_unref0 (self->priv->_right_node);
	_g_free0 (self->priv->_input);
	_g_free0 (self->priv->_output);
	self->priv->_entries = (_vala_KkcLanguageModelEntry_array_free (self->priv->_entries, self->priv->_entries_length1), NULL);
	KKC_TRELLIS_NODE_CLASS (kkc_bigram_trellis_node_parent_class)->finalize (obj);
}

static GType
kkc_bigram_trellis_node_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcBigramTrellisNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_bigram_trellis_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcBigramTrellisNode), 0, (GInstanceInitFunc) kkc_bigram_trellis_node_instance_init, NULL };
	GType kkc_bigram_trellis_node_type_id;
	kkc_bigram_trellis_node_type_id = g_type_register_static (KKC_TYPE_TRELLIS_NODE, "KkcBigramTrellisNode", &g_define_type_info, 0);
	KkcBigramTrellisNode_private_offset = g_type_add_instance_private (kkc_bigram_trellis_node_type_id, sizeof (KkcBigramTrellisNodePrivate));
	return kkc_bigram_trellis_node_type_id;
}

GType
kkc_bigram_trellis_node_get_type (void)
{
	static volatile gsize kkc_bigram_trellis_node_type_id__once = 0;
	if (g_once_init_enter (&kkc_bigram_trellis_node_type_id__once)) {
		GType kkc_bigram_trellis_node_type_id;
		kkc_bigram_trellis_node_type_id = kkc_bigram_trellis_node_get_type_once ();
		g_once_init_leave (&kkc_bigram_trellis_node_type_id__once, kkc_bigram_trellis_node_type_id);
	}
	return kkc_bigram_trellis_node_type_id__once;
}

