473,804 Members | 3,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A Tree class, my $0.02 contribution to the python community.

7 2063
Antoon Pardon wrote:
Comments are welcome:

http://www.pardon-sleeuwaegen.be/antoon/avltree.html

Does this type bear any relationship at all to what most people call a
tree, which is a bifurcated data structure? Or do you call it a tree for
some other reason?

Sounds like "cdict" might be a better name ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 12 '05 #2
Op 2005-10-12, Steve Holden schreef <st***@holdenwe b.com>:
Antoon Pardon wrote:
Comments are welcome:

http://www.pardon-sleeuwaegen.be/antoon/avltree.html
Does this type bear any relationship at all to what most people call a
tree, which is a bifurcated data structure? Or do you call it a tree for
some other reason?
The underlying implementation is an AVL balanced binary tree with
inorder threading.
Sounds like "cdict" might be a better name ...


I don't know. The python dictionary type with its name, seem to refer
to how it is implemented, so I thought Tree was an appropiate name
here as it is implemented as a tree.

--
Antoon Pardon
Oct 12 '05 #3
Steve Holden wrote:
Does this type bear any relationship at all to what most people call a
tree, which is a bifurcated data structure? Or do you call it a tree for
some other reason?


I'd think that the 'avl' part would answer that question.

!google avl tree

--

Joshua Simpson -- dataw0lf.org
Lead Network Administrator/Engineer Aero-Graphics Inc.
js******@aero-graphics.com
Oct 12 '05 #4
"Antoon Pardon" <ap*****@forel. vub.ac.be> wrote:
Comments are welcome:

http://www.pardon-sleeuwaegen.be/antoon/avltree.html


How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the next and previous
key respectively ? For instance nextkey would be equivalent to (untested):

def nextkey(self, key):
iter = self[key:]
first = iter.next()
if key not in self: return first
else: return iter.next()

Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) would be reasonable
additions.

And a question: what does step do if the keys are not integers since you restrict step to be integer
?

George
Oct 12 '05 #5
Antoon Pardon wrote:
I don't know. The python dictionary type with its name, seem to refer
to how it is implemented, so I thought Tree was an appropiate name
here as it is implemented as a tree.


I too had the impression you're talking about a tree-implementation, not
a mapping based on key compare operations.

Java calls such a thing TreeMap - so maybe TreeDict would be a suitable
name.

Diez
Oct 12 '05 #6
Op 2005-10-12, George Sakkis schreef <gs*****@rutger s.edu>:
"Antoon Pardon" <ap*****@forel. vub.ac.be> wrote:
Comments are welcome:

http://www.pardon-sleeuwaegen.be/antoon/avltree.html
How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the next and previous
key respectively ? For instance nextkey would be equivalent to (untested):


I'll file this as: I'll probably never need it, so I'm going to resist
the temptation to add them now. If i find out I'm wrong, I can still do
so later.
def nextkey(self, key):
iter = self[key:]
first = iter.next()
if key not in self: return first
else: return iter.next()
I think the if statement can be replaced by:

if not self.cmp(key, first) == 0: return first
Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) would be reasonable
additions.

And a question: what does step do if the keys are not integers since you restrict step to be integer
?


It skips keys/items/values.
radio = [ .... 'alfa', 'bravo', 'charlie', 'delta', 'echo', 'foxtrot', 'golf', 'hotel', 'india',
.... 'juliet', 'kilo', 'lima', 'mike', 'november', 'oscar', 'papa', 'quebec', 'romeo',
.... 'sierra', 'tango', 'uniform', 'victor', 'whiskey', 'x-ray', 'yankee', 'zulu' ]
letters = 'abcdefghijklmn opqrstuvwxyz'
from avltree import Tree
t=Tree(zip(radi o,letters))
t.keys('choco', None,3) ['delta', 'golf', 'juliet', 'mike', 'papa', 'sierra', 'victor', 'yankee'] t.values('burea u',None,4)

['c', 'g', 'k', 'o', 's', 'w']
What would you have in mind if step would have been a string here?

--
Antoon Pardon
Oct 13 '05 #7
Antoon Pardon <ap*****@forel. vub.ac.be> writes:
The underlying implementation is an AVL balanced binary tree with
inorder threading.


Dan Bernstein argues for switching from hash tables to crit-bit trees
(a/k/a Patricia trees), because of their guaranteed worst case
performance. He also claims:

"Crit-bit trees are faster than comparison-based structures such
as AVL trees and B-trees. They're also simpler, especially for
variable-length strings."

See:

http://cr.yp.to/critbit.html

See:

http://www.cs.rice.edu/~scrosby/hash/

for some stuff about the dangers of hash tables.
Oct 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2677
by: Xah Lee | last post by:
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); }
4
24137
by: hankssong | last post by:
Hi everyone, I'm wondering whether it's possible to construct a binary-tree using python. Since python don't have pointer, it can't dynamically allocate memory like C language. But some important data structures like linked list, binary-tree and hash table are closely linked with dynamic memory technology. Any help that can be provided would be greatly appreciated. Thanks in advance
5
1321
by: Brian L. Troutwine | last post by:
Lately I've been tinkering around with Erlang and have begun to sorely want some of its features in Python, mostly the ease at which new processes can be forked off for computation. To that end I've coded up a class I call, boringly enough, Process. It takes a function, its args and keywords and runs the function in another process using os.fork. Processes can be treated as callables to retrieve the return value of the passed in function. ...
6
6167
by: Travis | last post by:
Is there a community accepted best way to store a menu tree for an interface in a data structure. Ideally I would like something that searches fast so given a menu structure like this File / | \ / | \ Print Exit Edit / \ Copy Paste
0
1438
by: preetkanwal0678 | last post by:
Hello all, Am working on PYTHON +BRANWAVE(framework) Actually am Trying 2 make a tree menu using d both. Am not able 2 target the (.tmpl) files and not getting how 2 make frames in .tmpl file... Can anyone get me a demo screen 4 d same showing a tree on the left and when we click any link in the tree, corresponding page(.tmpl) page opens up on right... This is a simple Tree Example>>>>>>> file name="mytreeapp.py" import...
23
1688
by: bc90021 | last post by:
Hi All, Thanks in advance for any and all help! I have this code: g = open(fileName, 'a') where fileName is defined before the line it's used in. It works fine when I use it outside a thread class.
2
2253
by: Bart Kastermans | last post by:
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote: Thanks for the idea. I would expect the separation to lead to somewhat more code, but all the "checking the root" code would be separated out in the tree class. The node class would be very smooth. I'll try this when I have
6
1818
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS does not work; I have to write self.val = SS.val and the same for the other members (as shown below). Is there a better way to do this? In the below self is part of a parse tree, F is the parse tree of a function f with argument x. If a node...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.