search


Description:

public SequenceIter<G> search (G data, CompareDataFunc<G> cmp_func)

Returns an iterator pointing to the position where data would be inserted according to cmp_func and cmp_data .

cmp_func is called with two items of the this, and cmp_data. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

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

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

Example: Search:

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 ("3. dolor", (a, b) => {
return strcmp (a, b);
});

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

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

Parameters:

this

a Sequence

data

data for the new item

cmp_func

the function used to compare items in the sequence

cmp_data

user data passed to cmp_func

Returns:

an SequenceIter pointing to the position where data would have been inserted according to cmp_func and cmp_data