#include <glib.h>
#include <stdlib.h>

gint
_datacmp (gconstpointer s1, gconstpointer s2, gpointer user_data)
{
  g_return_val_if_fail (s1 != NULL, 0);
  g_return_val_if_fail (s2 != NULL, 0);
  return g_strcmp0 (s1, s2);
}

void
_foreachfunc (gchar* s, gpointer user_data)
{
  g_print ("dfg: %s\n", s);
}



int
main (int argc, char ** argv)
{
  GSequence* s;
  gchar* datastring;
  GSequenceIter* nd = NULL;
  gint i;
  s = g_sequence_new (g_free);
  datastring = g_strdup ("mystring2");
  nd = g_sequence_append (s, g_strdup (datastring));
  
  for(i = 0; i<20; i++)
  {
    nd = g_sequence_append (s, g_strdup_printf ("kjsdfh%i", i));
  }
  nd = NULL;
  
  /*  This lookup fails in 50 % */
  nd = g_sequence_lookup (s, "kjsdfh17", _datacmp, NULL);
  g_sequence_remove (nd);
  
  g_sequence_foreach (s, _foreachfunc, NULL);
  
  g_free (datastring);
  datastring = NULL;
  g_sequence_free (s);
  return 0;
}


/* gcc -o sequencetestcase sequencetestcase.c `pkg-config --libs --cflags glib-2.0` */
