Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106743

Re: how to convert code that uses cmp to python3

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: how to convert code that uses cmp to python3
Date Sat, 9 Apr 2016 18:03:48 +0200
Lines 35
Message-ID <mailman.128.1460217831.2253.python-list@python.org> (permalink)
References <57064D0D.1030701@rece.vub.ac.be> <CAPTjJmrGiQS9uhFU-+TQ4nUWQ2p4gmJoQitMotS0Ob--qm1iWg@mail.gmail.com> <5706C961.2000009@rece.vub.ac.be> <CAPTjJmrbL870mV1kU8nHar=bPyKZRmhKP-8iUs_tpYVo5vhhOA@mail.gmail.com> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be> <CAPTjJmrMv5O5vwrbfHJJCdiHi87naPOanhPmk4Ba_SLRgu1m4Q@mail.gmail.com> <5707BE18.1050805@rece.vub.ac.be> <CAPTjJmoMuqwg0Q_fp=qitC3wWkXYHtdqBNVGzO+3ToAmsgit8Q@mail.gmail.com> <5708C8B0.6050904@rece.vub.ac.be> <85twjb3su5.fsf@benfinney.id.au> <570910E2.3030400@rece.vub.ac.be> <CAPTjJmqeWACzrzka+5kQxO9Co42k7jRJzG_+cCqHkYO2OtQtMw@mail.gmail.com> <57091EA8.4080803@rece.vub.ac.be> <CAPTjJmrS=HW2fhDgZw22n5kcS4c+=b71rV50DkPPkKRdRW+QqA@mail.gmail.com> <570927E4.9000104@rece.vub.ac.be>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de x7YZcNRkqFSFR8+GTok9awk73s1gC0otRv6ZH/E6cxoA==
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cache': 0.05; 'keys,': 0.07; 'mentioned,': 0.07; 'so?': 0.07; 'subject:code': 0.07; 'dict': 0.09; 'objects.': 0.09; 'similar,': 0.09; 'python': 0.10; '2016': 0.16; '__lt__': 0.16; 'ah,': 0.16; 'cmp': 0.16; 'lookups': 0.16; 'python3.': 0.16; 'received:192.168.1.4': 0.16; 'received :adsl-dyn.isp.belgacom.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:python3': 0.16; 'wrote:': 0.16; 'duplicate': 0.18; 'tree': 0.18; 'tests': 0.18; 'do.': 0.22; 'keys': 0.22; 'tuples': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'point.': 0.27; 'converting': 0.27; 'key,': 0.29; 'strings,': 0.29; 'subject:that': 0.29; 'such.': 0.29; 'objects': 0.29; 'received:be': 0.30; 'supposed': 0.31; 'probably': 0.31; "can't": 0.32; 'implement': 0.32; 'common': 0.33; 'values.': 0.33; 'structure': 0.34; 'done': 0.35; 'something': 0.35; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'doing': 0.38; 'easily': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'avoid': 0.61; 'provide': 0.61; 'charset:windows-1252': 0.62; 'matter': 0.63; 'personal': 0.63; 'between': 0.65; 'angelico:': 0.84; 'answer,': 0.84; 'duplication': 0.84; 'ordered.': 0.84; 'pardon': 0.84; 'premature': 0.84; 'received:195.238': 0.84; 'schreef': 0.84; 'family.': 0.95
X-Belgacom-Dynamic yes
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result A2CbAACVJglX/2LF9VENUIUHulQBDYFzhg0CgWIUAQEBAQEBAYVOAQEEeBELGAkWDwkDAgECAUUTBgICsACNT4RbAQEIAh6GIYRLhQuFCgEEmASBVIw4jw2PJh4BAYQragGJKwEBAQ
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0
In-Reply-To <CAPTjJmrS=HW2fhDgZw22n5kcS4c+=b71rV50DkPPkKRdRW+QqA@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <570927E4.9000104@rece.vub.ac.be>
X-Mailman-Original-References <57064D0D.1030701@rece.vub.ac.be> <CAPTjJmrGiQS9uhFU-+TQ4nUWQ2p4gmJoQitMotS0Ob--qm1iWg@mail.gmail.com> <5706C961.2000009@rece.vub.ac.be> <CAPTjJmrbL870mV1kU8nHar=bPyKZRmhKP-8iUs_tpYVo5vhhOA@mail.gmail.com> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be> <CAPTjJmrMv5O5vwrbfHJJCdiHi87naPOanhPmk4Ba_SLRgu1m4Q@mail.gmail.com> <5707BE18.1050805@rece.vub.ac.be> <CAPTjJmoMuqwg0Q_fp=qitC3wWkXYHtdqBNVGzO+3ToAmsgit8Q@mail.gmail.com> <5708C8B0.6050904@rece.vub.ac.be> <85twjb3su5.fsf@benfinney.id.au> <570910E2.3030400@rece.vub.ac.be> <CAPTjJmqeWACzrzka+5kQxO9Co42k7jRJzG_+cCqHkYO2OtQtMw@mail.gmail.com> <57091EA8.4080803@rece.vub.ac.be> <CAPTjJmrS=HW2fhDgZw22n5kcS4c+=b71rV50DkPPkKRdRW+QqA@mail.gmail.com>
Xref csiph.com comp.lang.python:106743

Show key headers only | View raw


Op 09-04-16 om 17:31 schreef Chris Angelico:
> On Sun, Apr 10, 2016 at 1:24 AM, Antoon Pardon
> <antoon.pardon@rece.vub.ac.be> wrote:
>>
>> So? I need a structure that can easily give me an answer to the
>> following: Given key1 and key2 what are the the keys between them
>> with their corresponding values. As long as a dict can't provide
>> me with that answer, it doesn't matter that it will out perform
>> lookups in my trees.
> 
> Ah, okay. You can probably still take advantage of the other thing I
> mentioned, which was structuring your tree such that it's aware of the
> common prefixes, even if you can't go for O(1) hashing. That would
> drastically reduce the number of comparisons you have to do.

I think that would be a premature optization at this point. At this
moment I am just converting my python2 avltree module to python3.
This module doesn't care about how the keys are structured, it just
wants to know, given two keys, how are they ordered.

Now the original module can avoid doing some duplicate work by using
cmp instead of directly using the comparators. I am only prepared
to do something similar, because this is supposed to be a general
purpose tree and not one taylored to specific kinds of key objects.

The tests I have done show, the above is not an issue if my keys
are simple python objects like ints, strings, ... or tuples of
such.

And when I need some personal object as a key, I can avoid the
duplication by using some kind of cmp cache when I implement
__lt__ and family.

-- 
Antoon Pardon

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: how to convert code that uses cmp to python3 Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-09 18:03 +0200
  Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-09 19:32 +0300

csiph-web