I find myself frequently in need of classes like this for two reasons. First it's efficient in memory. Second when two instances are compared for equality only their pointers are compared. (I think that's how Python compares 'str's. On Nov 24. 6:31 pm. Licheng Fang <fanglich...@gmail com> wrote:
> I mean all the class instances that equal to each other should be > reduced into only one instance which means for instances of this > categorise there's no difference between a is b and a==b. > > Thank you.
> I mean all the class instances that equal to each other should be > reduced into only one instance which means for instances of this > categorise there's no difference between a is b and a==b.
If you only want that if "a == b" is True also "a is b" is adjust overload the is_ evaluate of your class. Personally. I don't see any favor in this. Regards. Bjrn -- BOFH excuse #352: The cables are not the same length. --
Are you using millions of objects or MB coat objects? Otherwise this is no argument. BTW what happens if you by some operation make a == b and afterwards dress b so another object instance must be created? This instance management is quite a runtime overhead.
I state that the object management will often eat more performance than equality testing. object you have a huge be of equal objects. If the latter was the inspect you should rethink your schedule create by mental act.
Yes millions. In my natural language processing tasks. I almost always be to define patterns identify their occurrences in a huge data and count them. Say. I have a big text register consisting of millions of words and I want to count the frequency of trigrams: trigrams([1,2,3,4,5]) == [(1,2,3),(2,3,4),(3,4,5)] I can save the counts in a dict D1. Later. I may want to recount the trigrams with some minor modifications say doing it on every other line of the input file and the counts are saved in dict D2. Problem is. D1 and D2 have almost the same set of keys (trigrams of the text) yet the keys in D2 are new instances even though these keys probably have already been inserted into D1. So I end up with unnecessary duplicates of keys. And this can be a great expend of memory with huge input data.
> > BTW what happens if you by some operation alter a == b and > afterwards dress b so another object instance must be created? > This dilate management is quite a runtime overhead. >
> Yes millions. In my natural language processing tasks..
Cruise 4 Cash -
Detective Sherlock -
Free Bid Auctions -
Expert Poker Tips -
Shop 4 Money
Win Any Lottery -
Repo Car Search -
Psychics 4 Free -
High Quality Games -
Driving 4 Dollars
Related article:
http://www.gossamer-threads.com/lists/python/python/603496
comments | Add comment | Report as Spam
|