home *** CD-ROM | disk | FTP | other *** search
- SPLAY TREE LIBRARY
- ==================
-
- This library contains the following files:
-
- splay.def Definition module for the splay tree library
- splay.mod Implementation of splay tree
- splayItem.def Definition module for data stored in the tree
- splayItem.mod Implementation module for data stored in
- the tree
- splayTest.mod A short test program
-
-
- For a full introduction to splay trees see
-
- Sleator D. and Tarjan R. "Self adjusting
- binary trees", JACM Vol 32. No 3, 1985, pp 652-
- 686.
-
-
- In short, splay trees are a form of balanced binary trees which
- moves every accessed node to the root. This means that the tree
- will behave very well when there is some form of locality in the
- data processed. Furthermore it can be shown that the amortized
- access cost is O(lgn) for the basic operations (insert, delete and
- find).
-
- The splay tree also has the nice property that an item accessed
- t operations ago can be located in O(lgt) time.
-
- All in all practical tests have shown splay trees to be an excellent
- substitution for the more well known r-b-trees or some other variations
- on balanced trees.
-
- Since modula2 lacks possibilities to create generic modules my
- approach is to provide a separate module which gives the operations
- and type of the element stored in the tree. This module
- (here called splayItem) must support operations to create, destroy
- and compare elements. This scheme provides for a fairly generic
- implementation, (see the test program and splayItem.[mod,def])
- In the test program supplied the create and destroy routines
- are empty since the objects doesn't use any dynamic memory. The
- prize to pay for the generic structure is a little overhead for
- each comparison.
-
- If speed is essential (as always) you may hard code the comparison
- beetween elements in the implementation if you are only working
- with simple types like integers or something like that. Or you
- might want to rewrite the code to handle the more classic
- variation with a key and a generic pointer stored in each
- node. These changes are trivial and shouldn't take long
- time to do.
-
- To the best of my knowledge this code is bug free. But if you
- do discover som irregularities please drop me a note.
-
- Johan Persson (ljp@sm.luth.se)
-
-
- ----
-
- Note0: You may encounter some difficulties when trying to
- compile the 'splayTest.mod' due to the lack of standard between
- different compilers in their I/O libraries. Though it should be
- fairly simpel just to change the name to your own routines which
- prints a string, a cardinal and so on.
-
- Note1: This code implements the more efficient top-down splaying as
- described in section 4 of original paper (see above).
-
- Note2: This implementation has been augumented with operations
- to retrive the rank of the element stored in the tree, (i.e their
- position when making an inorder tree walk). This operations take time
- O(lgn), but to achive this we have to pay a prize when making
- the basic operations (insert,delete,find), this means that these
- operations now take O(n) time instead. If you find this unexceptable
- you may modify the source by simply removing the calls to 'fixRank' at
- the end of (insert,delete,find). NOTE: this will make the rank operations
- unusable! The basic problem is that we must maintain the weight of
- each element, and each basic operations restructure the tree so we
- must recalculate the weights for each node bottom up.
-
-
- ---
- Johan Persson E-mail: ljp@sm.luth.se
- Dept. of Computer Science
- Technical University of Lulea
- S-951 87 Lulea
-
-