search_iter


Description:

public SequenceIter<G> search_iter (G data, SequenceIterCompareFunc<G> iter_cmp)

Like search, but uses a SequenceIterCompareFunc instead of a CompareDataFunc as the compare function.

iter_cmp is called with two iterators pointing into this. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

If you are simply searching for an existing element of the sequence, consider using lookup_iter.

This function will fail if the data contained in the sequence is unsorted.

Example: Search, iter-based:

public static int main (string[] args) {
Sequence<string> seq = new Sequence<string> ();
// sorted data:
seq.append ("1. Lorem");
seq.append ("2. ipsum");
seq.append ("4. sit");
seq.append ("5. amet");

SequenceIter<string> iter = seq.search_iter ("3. dolor", (a, b) => {
return strcmp (a.get (), b.get ());
});

// Output: ``4. sit``
print ("%s\n", iter.get ());

return 0;
}

valac --pkg glib-2.0 GLib.Sequence.search_iter.vala

Parameters:

this

a Sequence

data

data for the new item

iter_cmp

the function used to compare iterators in the sequence

cmp_data

user data passed to iter_cmp

Returns:

a SequenceIter pointing to the position in this where data would have been inserted according to iter_cmp and cmp_data