[Cython] list.index(instance) by identity or __eq__?
Robert Bradshaw
robertwb at math.washington.edu
Fri Oct 10 10:02:56 CEST 2008
On Oct 10, 2008, at 12:28 AM, Aaron DeVore wrote:
> Tragically, I can't show my implementation of __eq__. However, I will
> say this: I absolutely cannot change __eq__ to work with identities.
>
> For a relatively short list (usually 0-20 items, sometimes up to 1000)
> would this work and still be blindingly fast? "----" indicates
> indentation.:
>
> int index
> for index from 0 <= index < len(a_list):
> ----if a_list[index] is my_type_instance:
> --------break
This will compare on identity, if that's what you want then it should
be quite fast.
> Or would I need to do this to get correct behavior:
> int index
> for index from 0 <= index < len(a_list):
> ----if id(a_list[index]) == id(my_type_instance):
> --------break
This is essentially how list.index() is implemented.
>
> 2008/10/9 Lisandro Dalcin <dalcinl at gmail.com>:
>> On Wed, Oct 8, 2008 at 4:15 PM, Aaron DeVore
>> <aaron.devore at gmail.com> wrote:
>>> I have a my_type.__eq__
>>> function but it doesn't give the correct behavior. Which behavior
>>> does
>>> Cython use?
>>
>> Could you show us the way you implemented your __eq__ method?
>>
>>
>>
>> --
>> Lisandro Dalcín
>> ---------------
>> Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
>> Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
>> Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
>> PTLC - Güemes 3450, (3000) Santa Fe, Argentina
>> Tel/Fax: +54-(0)342-451.1594
>> _______________________________________________
>> Cython-dev mailing list
>> Cython-dev at codespeak.net
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
More information about the Cython-dev
mailing list