mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
Add a new 'real_sequence' field. (g_sequence_new): Initialize
2007-02-03 Soren Sandmann <sandmann@daimi.au.dk> * glib/gsequence.c (struct _GSequence): Add a new 'real_sequence' field. (g_sequence_new): Initialize real_sequence to the sequence (g_sequence_sort_iter): Set real_sequence of the temporary sequence to the real sequence. (g_sequence_sort_changed_iter): Same (g_sequence_insert_sorted_iter): Same (g_sequence_search_iter): Same (g_sequence_iter_get_sequence): Return real_sequence * tests/sequence-test.c (compare_iters): Insert assertions that the iters point to the sequence being manipulated. svn path=/trunk/; revision=5323
This commit is contained in:
parent
674c4df418
commit
576a5d4127
15
ChangeLog
15
ChangeLog
@ -1,3 +1,18 @@
|
||||
2007-02-03 Soren Sandmann <sandmann@daimi.au.dk>
|
||||
|
||||
* glib/gsequence.c (struct _GSequence): Add a new 'real_sequence'
|
||||
field.
|
||||
(g_sequence_new): Initialize real_sequence to the sequence
|
||||
(g_sequence_sort_iter): Set real_sequence of the temporary
|
||||
sequence to the real sequence.
|
||||
(g_sequence_sort_changed_iter): Same
|
||||
(g_sequence_insert_sorted_iter): Same
|
||||
(g_sequence_search_iter): Same
|
||||
(g_sequence_iter_get_sequence): Return real_sequence
|
||||
|
||||
* tests/sequence-test.c (compare_iters): Insert assertions that
|
||||
the iters point to the sequence being manipulated.
|
||||
|
||||
2007-02-03 Soren Sandmann <sandmann@daimi.au.dk>
|
||||
|
||||
* glib/gsequence.[ch]: New files implementing GSequence, a list
|
||||
|
@ -30,6 +30,15 @@ struct _GSequence
|
||||
GSequenceNode * end_node;
|
||||
GDestroyNotify data_destroy_notify;
|
||||
gboolean access_prohibited;
|
||||
|
||||
/* The 'real_sequence' is used when temporary sequences are created
|
||||
* to hold nodes that being rearranged. The 'real_sequence' of such
|
||||
* a temporary sequence points to the sequence that is actually being
|
||||
* manipulated. The only reason we need this is so that when the
|
||||
* sort/sort_changed/search_iter() functions call out to the application
|
||||
* g_sequence_iter_get_sequence() will return the correct sequence.
|
||||
*/
|
||||
GSequence * real_sequence;
|
||||
};
|
||||
|
||||
struct _GSequenceNode
|
||||
@ -161,6 +170,8 @@ g_sequence_new (GDestroyNotify data_destroy)
|
||||
seq->end_node = node_new (seq);
|
||||
|
||||
seq->access_prohibited = FALSE;
|
||||
|
||||
seq->real_sequence = seq;
|
||||
|
||||
return seq;
|
||||
}
|
||||
@ -697,12 +708,13 @@ g_sequence_sort_iter (GSequence *seq,
|
||||
end = g_sequence_get_end_iter (seq);
|
||||
|
||||
tmp = g_sequence_new (NULL);
|
||||
tmp->real_sequence = seq;
|
||||
tmp->access_prohibited = TRUE;
|
||||
|
||||
seq->access_prohibited = TRUE;
|
||||
|
||||
g_sequence_move_range (g_sequence_get_begin_iter (tmp), begin, end);
|
||||
|
||||
tmp->access_prohibited = TRUE;
|
||||
seq->access_prohibited = TRUE;
|
||||
|
||||
while (g_sequence_get_length (tmp) > 0)
|
||||
{
|
||||
GSequenceNode *node = g_sequence_get_begin_iter (tmp);
|
||||
@ -765,6 +777,8 @@ g_sequence_sort_changed_iter (GSequenceIter *iter,
|
||||
seq->access_prohibited = TRUE;
|
||||
|
||||
tmp_seq = g_sequence_new (NULL);
|
||||
tmp_seq->real_sequence = seq;
|
||||
|
||||
node_unlink (iter);
|
||||
node_insert_before (tmp_seq->end_node, iter);
|
||||
|
||||
@ -824,6 +838,8 @@ g_sequence_insert_sorted_iter (GSequence *seq,
|
||||
* is the only kind of compare functions GtkTreeView can use.
|
||||
*/
|
||||
tmp_seq = g_sequence_new (NULL);
|
||||
tmp_seq->real_sequence = seq;
|
||||
|
||||
new_node = g_sequence_append (tmp_seq, data);
|
||||
|
||||
node_insert_sorted (seq->end_node, new_node,
|
||||
@ -885,6 +901,8 @@ g_sequence_search_iter (GSequence *seq,
|
||||
* is the only kind of compare functions GtkTreeView can use.
|
||||
*/
|
||||
tmp_seq = g_sequence_new (NULL);
|
||||
tmp_seq->real_sequence = seq;
|
||||
|
||||
dummy = g_sequence_append (tmp_seq, data);
|
||||
|
||||
node = node_find_closest (seq->end_node, dummy,
|
||||
@ -910,9 +928,16 @@ g_sequence_search_iter (GSequence *seq,
|
||||
GSequence *
|
||||
g_sequence_iter_get_sequence (GSequenceIter *iter)
|
||||
{
|
||||
g_return_val_if_fail (iter != NULL, NULL);
|
||||
GSequence *seq;
|
||||
|
||||
return get_sequence (iter);
|
||||
g_return_val_if_fail (iter != NULL, NULL);
|
||||
|
||||
seq = get_sequence (iter);
|
||||
|
||||
/* For temporary sequences, this points to the sequence that
|
||||
* is actually being manipulated
|
||||
*/
|
||||
return seq->real_sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +127,7 @@ compare_items (gconstpointer a,
|
||||
{
|
||||
const Item *item_a = fix_pointer (a);
|
||||
const Item *item_b = fix_pointer (b);
|
||||
|
||||
|
||||
if (item_a->number < item_b->number)
|
||||
return -1;
|
||||
else if (item_a->number == item_b->number)
|
||||
@ -169,12 +169,19 @@ compare_iters (gconstpointer a,
|
||||
gconstpointer b,
|
||||
gpointer data)
|
||||
{
|
||||
GSequence *seq = data;
|
||||
GSequenceIter *iter_a = (GSequenceIter *)a;
|
||||
GSequenceIter *iter_b = (GSequenceIter *)b;
|
||||
/* compare_items() will fix up the pointers */
|
||||
Item *item_a = g_sequence_get (iter_a);
|
||||
Item *item_b = g_sequence_get (iter_b);
|
||||
|
||||
if (seq)
|
||||
{
|
||||
g_assert (g_sequence_iter_get_sequence (iter_a) == seq);
|
||||
g_assert (g_sequence_iter_get_sequence (iter_b) == seq);
|
||||
}
|
||||
|
||||
return compare_items (item_a, item_b, data);
|
||||
}
|
||||
|
||||
@ -372,7 +379,7 @@ run_random_tests (guint32 seed)
|
||||
case SORT_ITER:
|
||||
{
|
||||
g_sequence_sort_iter (seq->sequence,
|
||||
(GSequenceIterCompareFunc)compare_iters, NULL);
|
||||
(GSequenceIterCompareFunc)compare_iters, seq->sequence);
|
||||
g_queue_sort (seq->queue, compare_iters, NULL);
|
||||
check_sorted (seq);
|
||||
}
|
||||
@ -538,7 +545,7 @@ run_random_tests (guint32 seed)
|
||||
iter = g_sequence_insert_sorted_iter (seq->sequence,
|
||||
new_item (seq),
|
||||
(GSequenceIterCompareFunc)compare_iters,
|
||||
NULL);
|
||||
seq->sequence);
|
||||
|
||||
g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
|
||||
}
|
||||
@ -593,7 +600,7 @@ run_random_tests (guint32 seed)
|
||||
{
|
||||
g_sequence_set (iter, new_item (seq));
|
||||
g_sequence_sort_changed_iter (iter,
|
||||
(GSequenceIterCompareFunc)compare_iters, NULL);
|
||||
(GSequenceIterCompareFunc)compare_iters, seq->sequence);
|
||||
|
||||
g_queue_delete_link (seq->queue, link);
|
||||
g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
|
||||
@ -737,7 +744,7 @@ run_random_tests (guint32 seed)
|
||||
item = new_item (seq);
|
||||
search_iter = g_sequence_search_iter (seq->sequence,
|
||||
item,
|
||||
(GSequenceIterCompareFunc)compare_iters, NULL);
|
||||
(GSequenceIterCompareFunc)compare_iters, seq->sequence);
|
||||
|
||||
insert_iter = g_sequence_insert_sorted (seq->sequence, item, compare_items, NULL);
|
||||
|
||||
@ -792,13 +799,11 @@ run_random_tests (guint32 seed)
|
||||
|
||||
if (g_sequence_get_length (seq->sequence) > 0)
|
||||
{
|
||||
g_assert (!g_sequence_iter_is_begin (
|
||||
g_sequence_get_end_iter (seq->sequence)));
|
||||
g_assert (!g_sequence_iter_is_begin (g_sequence_get_end_iter (seq->sequence)));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (g_sequence_iter_is_begin (
|
||||
g_sequence_get_end_iter (seq->sequence)));
|
||||
g_assert (g_sequence_iter_is_begin (g_sequence_get_end_iter (seq->sequence)));
|
||||
}
|
||||
|
||||
g_assert (g_sequence_iter_is_begin (g_sequence_get_begin_iter (seq->sequence)));
|
||||
@ -815,13 +820,11 @@ run_random_tests (guint32 seed)
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
g_assert (!g_sequence_iter_is_end (
|
||||
g_sequence_get_begin_iter (seq->sequence)));
|
||||
g_assert (!g_sequence_iter_is_end (g_sequence_get_begin_iter (seq->sequence)));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (g_sequence_iter_is_end (
|
||||
g_sequence_get_begin_iter (seq->sequence)));
|
||||
g_assert (g_sequence_iter_is_end (g_sequence_get_begin_iter (seq->sequence)));
|
||||
}
|
||||
|
||||
g_assert (g_sequence_iter_is_end (g_sequence_get_end_iter (seq->sequence)));
|
||||
@ -1083,12 +1086,10 @@ test_insert_sorted_non_pointer (void)
|
||||
|
||||
for (j = 0; j < 10000; j++)
|
||||
{
|
||||
g_sequence_insert_sorted (
|
||||
seq, GINT_TO_POINTER (g_random_int()),
|
||||
g_sequence_insert_sorted (seq, GINT_TO_POINTER (g_random_int()),
|
||||
compare, NULL);
|
||||
|
||||
g_sequence_insert_sorted_iter (
|
||||
seq, GINT_TO_POINTER (g_random_int()),
|
||||
g_sequence_insert_sorted_iter (seq, GINT_TO_POINTER (g_random_int()),
|
||||
compare_iter, NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user