FOATH Uirnenslons
Total Page:16
File Type:pdf, Size:1020Kb
FOATH UIrnEnSlOnS FORTH INTEREST GROUP Volume II P.O. Box 1 105 Number 4 San Carlos, CA 94070 Price $2.00 Historical Perspective 1Publisher’s Col um n 96 - Balanced Tree 108 Letters 109 The Execution Variable and Array 11I, I1 8,119 Meetings 112 Project Benchmark 113 IPS - A German FORTH-Dialect The CASE, SEL, 116 and COND Structures Published by Forth Interest Group Volume II No. 4 November/December 1980 PUBLISHER’S COLUMN Publisher Roy C. Martens Editorial Review Board Bill Ragsdale We’re deep into the planning and arrangements for Dave Boulton the FIG Convention and the FOAML Conference. If you Kim Harris haven’t made your reservations, call right away, we John James might be able to get you into the FORML Conference or Dave Kilbridge the Convention Banquet. Plan on coming to the Con- George Maverick vention anyway. Remember the dates and places :re. FORTH DIMENSIONS solicits editorial material, FORML Conference, November 26.27,828 comments and letters. No responsibility is assumed for Asilomar, CA accuracy of material submitted. ALL MATERIAL PUBLISHED BY THE FORTH INTEREST GROUP IS IN FIG Convention, November 29 THE PUBLIC DOMAIN. Information in FORTH Villa Hotel, San Mateo, CA DIMENSIONS may be reproduced with credit given to the author and the Forth Interest Group. The other big news! FORTH-79 STANDARD is available!!! Call (41 5) 962-8653 or send in your order, Subscription to FORTH DIMENSIONS is free with today! $1 O.OO! membership in the Forth Interest Group at $1 2.00 per year ($1 5.00 overseas). For membership, change of Many publications are printing information about address and/or to submit material. the address is: FORTH. We don’t get them all, so please send in copies so we can thank the editors and add to our collection. Forth Interest Group P.O. Box 1 105 FIG had a booth at the Mini/Micro show and much San Carlos. CA 94070 interest was generated among attendees which carried over into a number of manufacturers that were exhibit- ing. Membership is fast approaching 2,000. We now HISTORICAL PERSPECTIVE have members all over the world including the People’s Republic of China and Yugoslavia. See the listings of meetings for information about how you can form a FIG chapter. Just a few easy steps and you’ll have a time FORTH was created by Mr. Charles H. Moore in and place to share information. 1969 at the National Radio Astronomy Observatory, Charlottesville, VA. It was created out of dissatisfaction Look forward to seeing everyone at the FORML with available programming toots, especially for obser- Conference and the FIG Convention. vatory automation. Mr. Moore and several associates formed FORTH, Roy Martens Inc. in 1973 for the purpose of licensing and support of the FORTH Operating System and Programming Lan- guage, and to supply application programming to meet customers’ unique requirements. The Forth Interest Group is centered in Northern California, although our membership of 2,000 is world- wide. It was formed in 1978 by FORTH programmers to encourage use of the language by the interchange of ideas through seminars and publications. Page 95 FORTH DIMENSIONS II/4 guaranteed worst case performance of BALANCED TREE far less than a millisecond even in DELETION IN FASL fairly large (over five hundred node) trees. Douglas H. Currie, Jr. In FUNCTIONAL* systems, FASL trees Nashua, NH are used in a line editor, data stor- age directories, FACT (a truth table compiler), message routing tables, Abstract microcomputer assemblers, as well as the FASL dictionary. A general pur- FAS L ( Func t iona 1 Automat ion pose microassembler uses a balanced Systems Language) is a derivative of tree (fields) of balanced trees (con- FORTH containing significant modifi- tents) to describe the target micro- cations. This paper discusses one of instruction. The use of multiple these, the FASL tree, an implementa- trees allows identical keys in tion of the AVL (height balanced) different contexts (e.g., label names tree. FASL trees are a data type of and macro names). the language, and are used in the implementation of the dictionary. An The height-balanced tree was first algorithm for deletion in FASL trees proposed by two Russian mathemati- is presented, as well as a FASL cians, G. M. Adel'son-Vel'skiy and E. program to implement the algorithm. M. Landis in 1962 (hence -AVL tree). The idea is to maintain a binary tree Kev Words and Phrases so that the height of the subtrees at any node differ by at most one. The deletion, height-balanced trees, technique incurs a penalty of only binary trees, search trees, FORTH. two extra bits per node (FASL uses an 8-bit byte), and makes it possible to CR Categories search for, insert, or delete a node with a worst case of O(1og N) opera- 3.7, 4.10, 4.20, 4.34, 5.25, 5.31 tions (where N is the number of nodes). Introduction to Height-Balanced Trees Introduction to FASL Trees The use of balanced trees has become almost commonplace in data Algorithms for search and inser- base management, and is seeing limited tion in AVL trees are presented by use in symbol tables. Many systems Knuth (The Art of Computer Program- would benefit from the use of balanced ming, Vol. 3, Section 6.2.3); these trees, but their designers could not two algorithms were implemented in afford the time to develop the algo- machine code and (along with Indirect rithms. A case in point is the Threaded Code) became the basis for extensive use of hashing in "high- PASL. The deletion algorithm was not speed" microcomputer assemblers. implemented at this time for two Hashing techniques have significantly primary reasons: Knuth didn't give improved the performance of many it, FASL didn't "need" it. Deletions assemblers, but analysis of these occur much more rarely than inser- routines shows a best case perfor- tions or searches; FASL lived for mance on the order of several milli- over a year with no delete operation. seconds (due to the inefficiency of division, or pseudo-random number *Functional Automation Could Inc. generation on microprocessors). FASL 3 Graham Drive trees, on the other hand, have a Nashua, NH 03060 FORTH DIMENSIONS 11/4 Page 96 For example, when a file was deleted balance factor is always minus one, from a FASL directory, the entire zero, or plus one. directory was reconstructed without the "deleted" node. The time penalty incurred was not significant because directories are small (for FASL trees), and had to be copied anyway to be sent to the disk. (FASL lives I- *€ID in a message enviroment. The disk is :onmi in another Cyblok*). After an overview of FASL trees and their use, the remainder of this paper will deal with the development of a FASL tree deletion pragram in FASL. For an introduction to binary search trees, see Knuth (The Art of Computer Programming, Vol. 3). I' I FASL trees are composed of a number of sixteen byte nodes (see Figure 1). The tree is identified with the address of its head node. From the head node we may find the root node, and thus the entire tree. The head node contains a pointer to its root node, a pointer to its available nodes list, and an integer which is the ':Cult 1 tree ' s he igh t . All nodes other than the head node contain an eight byte key, a left The insertion routine obtains new link, a right link, a one byte balance nodes from the free nodes list. This factor, and three uncommitted bytes. list is simply a number of nodes The key is used to access the node. linked with their right links. A Given a key, the search routine null right link indicates the end of compares it to the key at the root the free nodes list. When the inser- node. If it is less, the search tion routine needs a free node, it continues with the node identified obtains its address from the free (pointed to) by the left link. If it nodes list pointer in the head node, is greater, the search continues with and replaces it with the right link the node identified by the right link. of that node. If the free nodes list The search terminates when it matches pointer is null, then the tree is the key (success), or reaches a null full. link (failure). The null link is represented by zero. The balance The technique used by the insertion factor is the height of the right routine to maintain tree balance is subtree minus the height of the left essentially the same as for deletion. subtree. The insertion routine always Basically, four cases arise in inser- leaves the tree balanced, i.e., the tion when the tree must be rebalanced: single or double rotation, left or "Cyblok is a registered trademark of right. The discussion is postponed Functional Automation/Gould Inc. until the section on deletion. Page 97 FORTH DIMENSIONS 1114 To get a feeling for the efficiency Later, the data may be retrieved of FASL trees, consider a dictionary onto the stack as follows: of five hundred nodes. If this dic- tionary was stored as a linked list, PAD SYMBOLS FIND a worst case access time of five hun- IF F#@ dred compares would be incurred, with ELSE FAIL FAIL FI an average access time of two hundred fifty compares. Stored as a FASL If the string in PAD is the same as tree, this dictionary has a worst case was used in the preceding example to access time of nine compares, an insert the node, then the data re- average of eight.