Re: [Vala] customizing the equal_func on arraylist



Hi,

2009/12/15 Lucas Deters <lucasdeters+vala gmail com>:
Hello,

Can someone show me how to pass a customized "equal_func" function to the
arraylist?
All samples I found are working with strings , but I need an custom
comparator.

ArrayList<string> list = new ArrayList<string> ( str_equal );
ArrayList<MyClass> list = new ArrayList<MyClass> ( ??? );
There is direct_equal if you want to compare on adresses, but if you
want to compare on something else, you can define your own equality
function.
e.g.
bool my_class_equal (MyClass a, MyClass b) {
    return a.some_field == b.some_field;
}
(you may need to cast it to an EqualFunc when passing it as a parameter though)

HTH,
Abderrahim



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]