1 SOFTWARE PRACTICE AND EXPERIENCE, VOL. 25(12), (DECEMBER 1995) Ropes: an Alternative to Strings hans-j. boehm, russ atkinson and michael plass Xerox PARC, 3333 Coyote Hill Rd., Palo Alto, CA 94304, U.S.A. ( boehm parc.xerox.com) SUMMARY Programming languages generally provide a string or text type to allow manipulation of sequences of characters. This type is usually of crucial importance, since it is normally mentioned in most interfaces between system components. We claim that the traditional implementations of strings, and often the supported functionality, are not well suited to such general-purpose use. They should be confined to applications with specific, and unusual, performance requirements. We present ropes or heavyweight strings as an alternative that, in our experience leads to systems that are more robust, both in functionality and in performance. Ropes have been in use in the Cedar environment almost since its inception, but this appears to be neither well-known, nor discussed in the literature. The algorithms have been gradually refined. We have also recently built a second similar, but somewhat lighter weight, C-language implementation, which is included in our publically released garbage collector distribution. 1 We describe the algorithms used in both, and give some performance measurements for the C version. key words: character strings; concatenation; Cedar; immutable; C; balanced trees WHAT S WRONG WITH STRINGS? Programming languages such as C and traditional Pascal provide a built-in notion of strings as essentially fixed length arrays of characters. The language itself provides the array primitives for accessing such strings, plus often a collection of library routines for higher level operations such as string concatenation. Thus the implementation is essentially constrained to represent strings as contiguous arrays of characters, with or without additional space for a length, expansion room, etc. There is no question that such data structures are occasionally appropriate, and that an array of characters data structure should be provided. On the other hand, since the character string type will be used pervasively to communicate between modules of a large system, we desire the following characteristics: 1. Immutable strings, i.e. strings that cannot be modified in place, should be well supported. A procedure should be able to operate on a string it was passed without danger of accidentally modifying the caller s data structures. This becomes particularly important in the presence of concurrency, where in-place updates to strings would often have to be properly synchronized. (Although they are not the norm, immutable strings have been provided by SNOBOL and BASIC since the mid 1960s. Thus this idea is hardly new.) 2. Commonly occurring operations on strings should be efficient. In particular CCC /95/ Received 26 July by John Wiley & Sons, Ltd. Revised 7 April 1995
2 1316 h.-j. boehm, r. atkinson and m. plass (non-destructive) concatenation of strings and non-destructive substring operations should be fast, and should not require excessive amounts of space. 3. Common string operations should scale to long strings. There should be no practical bound on the length of strings. Performance should remain acceptable for long strings. (All of us have seen symptoms of the violation of this requirement. For instance, the vi editor on most UNIX(TM) systems is unusable on many text files due to a line length limit. An unchecked input limit in fingerd supported the Morris internet worm. 2 A six-month-old child randomly typing at a workstation would routinely crash some older UNIX kernels due to a buffer size limitation, etc.) 4. It should be as easy as possible to treat some other representation of sequence of character (e.g. a file) as a string. Functions on strings should be maximally reusable. Strings represented as contiguous arrays of characters, as in C or Pascal, violate most of these. Immutable strings may or may not be supported at the language level. Concatenation of two immutable strings often involves copying both, and thus becomes intolerably inefficient, in both time and space, for long strings. The substring operation usually (though not necessarily) exhibits similar problems. Since strings are stored contiguously, any copying of strings results in the allocation of large chunks of storage, which may also result in substantial memory fragmentation. (For long strings, we have observed this to be a problem even for some compacting garbage collectors, since they are likely to avoid moving very large objects.) As mentioned above, it is very common for application programs not to scale to long string inputs at all. When they do, they commonly use special purpose data structures to represent those strings in order to obtain acceptable performance. We are not aware of any standard UNIX text editors that use a general purpose string representation for the file being edited. Doing so would make character insertion in long files intolerably slow. The approach we propose makes that practical. In order to maximize reusability of string functions, it should be easy to coerce other representations into standard strings. This is always possible by copying the characters and building the appropriate string representation. But this is undesirable if, for example, the original sequence is a long file, such that only the first few characters are likely to be examined. We would like to be able to convert files into strings without first reading them. AN ALTERNATIVE In order to allow concatenation of strings to be efficient in both time and space, it must be possible for the result to share much of the data structure with its arguments. This implies that fully manual storage management (e.g. based on explicit malloc/free) is impractical. (It can be argued that this is true even with conventional string representations. Manual storage management typically results in much needless string copying.) Though an explicitly reference counted implementation can be built, we will assume automatic garbage collection. Since concatenation may not copy its arguments, the natural alternative is to represent such a string as an ordered tree, with each internal node representing the concatenation of its children, and the leaves consisting of flat strings, usually
3 ropes: an alternative to strings 1317 represented as contiguous arrays of characters. Thus the string represented by a tree is the concatenation of its leaves in left-to-right order, as shown in Figure 1. We refer to character strings represented as a tree of concatenation nodes as ropes. (This is a little sloppy. A rope may contain shared subtrees, and is thus really a directed acyclic graph, where the out-edges of each vertex are ordered. We will continue to be sloppy.) Ropes can be viewed as search trees that are indexed by position. If each vertex contains the length of the string represented by the subtree, then minimal modifications of the search tree algorithms yield the following operations on ropes: 1. Fetch ith character. A simple search tree look-up. Rather than examining the subtree containing the right key, we examine the tree containing the proper position, as determined by the length fields. 2. Concatenate two ropes. Search tree concatenation as defined in Reference Substring. Two search tree split operations, as defined in Reference Iterate over each character. Left-to-right tree traversal. The first three of the above operations can be performed in a time logarithmic in the length of the argument, using, for example, B-trees or AVL trees. 3,4 Note that since strings are immutable, any nodes that would be modified in the standard version of the algorithm, as well as their ancestors, are copied. Only logarithmically many nodes need be copied. The last can be performed in linear time for essentially any search tree variant. Thus both concatenation and substring operations (other than for very short substrings) are asymptotically faster than for conventional flat strings. The last exhibits roughly the same performance. The first is somewhat slower, but usually infrequent. In practice, we modify this in two ways. Concatenation is often a sufficiently important operation that it should run in unit, not logarithmic, time. Long output strings are typically built by concatenating short ones. For example, compilers generating assembly language output may do so by concatenating strings in memory. 5 Hence binary concatenation normally simply adds a root node, and does not rebalance the tree. The rebalancing operation is either performed selectively, or invoked explicitly. Effectively this trades speed of the substring and fetch operations for better concatenation performance. Iteration over a rope is basically unaffected. (Theoretically it is possible to guarantee that the first three operations run in amortized logarithmic time, the iteration operation runs in linear time, and individual concatenations are performed in constant time by using a splay tree based representation, 6,7 in which each node represents the concatenation of a (possibly Figure 1. Rope representation of The quick brown fox
4 1318 h.-j. boehm, r. atkinson and m. plass empty) rope, a (non-empty) flat string, and another rope. This appears impractical in our situation, since the fetch operation requires large amounts of allocation and data structure modification. Furthermore, in a multithreaded environment, the fetch operation appears to require locking.) It is useful to introduce additional kinds of tree nodes. At a minimum, we allow a second kind of leaf node containing at least a length and a user-defined function for computing the ith character in the string. This allows other representations of character sequences (e.g. files) to be treated as ropes without copying. It may further be useful to introduce substring nodes, so that long substrings of flat ropes do not require copying. ALGORITHMS We briefly discuss the implementation of the more common operations. We will largely ignore nodes containing user-defined functions, in that they do not affect the algorithms significantly. We assume that all leaves are non-empty. We exclude empty ropes from consideration; they are a trivial special case. Note that all operations are completely non-destructive. They may be performed without locking in a multithreaded environment. Concatenation In the general case, concatenation involves simply allocating a concatenation node containing two pointers to the two arguments. For performance reasons, it is desirable to deal with the common case in which the right argument is a short flat string specially. If both arguments are short leaves, we produce a flat rope (leaf) consisting of the concatenation. This greatly reduces space consumption and traversal times. If the left argument is a concatenation node whose right son is a short leaf, and the right argument is also a short leaf, then we concatenate the two leaves, and then concatenate the result to the left son of the left argument. Together, these two special cases guarantee that if a rope is built by repeatedly concatenating individual characters to its end, we still obtain a rope with leaves of reasonable size. They also greatly reduce the imbalance of the resulting trees. Since the length of ropes is, in practice, bounded by the word size of the machine, we can place a bound on the depth of balanced ropes. The concatenation operation checks whether the resulting tree significantly exceeds this bound. If so, the rope is explicitly rebalanced (see below). This has several benefits: 1. The balancing operation is only invoked implicitly for long ropes, and then rarely. Each balancing operation will normally reduce the depth of the rope to considerably below the threshold. 2. Recursive operations on ropes require a bounded amount of stack space. 3. Paths in the tree can be represented in a fixed amount of space. This is important for the C implementation (see below). Substring The substring operation on structured ropes can be easily implemented. We assume that the substring operation on leaves simply copies the relevant section of the leaf, and deals with negative start arguments and over-length arguments correctly.
5 ropes: an alternative to strings 1319 substr(concat(rope1,rope2),start,len) = let left = if start 0 and len length(rope1) then rope1 else substr(rope1,start,len) right = if start length(rope1) and start + len length(rope1) + length(rope2) then rope2 else substr(rope2,start-length(rope1), len-length(left)) in concat(left,right) This involves one recursive call for each tree node along the left or right boundary of the substring. Hence its running time is bounded asymptotically by the tree height. There is a trade-off between this kind of eager substring computation, and one in which substrings are computed lazily by introducing special substring nodes, representing unevaluated substrings. In practice we want to use lazy substring computations at least when we compute long substrings of very long flat ropes (e.g. a function node representing a lazily-read file). Rebalancing Rebalancing produces a balanced version of the argument rope. The original is unaffected. We define the depth of a leaf to be 0, and the depth of a concatenation to be one plus the maximum depth of its children. Let F n be the nth Fibonacci number. A rope of depth n is balanced if its length is at least F n+2, e.g. a balanced rope of depth 1 must have length at least 2. Note that balanced ropes may contain unbalanced subropes. The rebalancing operation maintains an ordered sequence of (empty or) balanced ropes, one for each length interval [F n, F n+1 ), for n 2. We traverse the rope from left to right, inserting each leaf into the appropriate sequence position, depending on its length. The concatenation of the sequence of ropes in order of decreasing length is equivalent to the prefix of the rope we have traversed so far. Each new leaf x is inserted into the appropriate entry of the sequence. Assume that x s length is in the interval [F n, F n+1 ), and thus it should be put in slot n (which also corresponds to maximum depth n 2). If all lower and equal numbered levels are empty, then this can be done directly. If not, then we concatenate ropes in slots 2,...,(n 1) (concatenating onto the left), and concatenate x to the right of the result. We then continue to concatenate ropes from the sequence in increasing order to the left of this result, until the result fits into an empty slot in the sequence. The concatenation we form in this manner is guaranteed to be balanced. The concatenations formed before the addition of x each have depth at most one more than is warranted by their length. If slot n 1 is empty then the concatenation of shorter ropes has depth at most n 3, so the concatenation with x has depth n 2, and is thus balanced. If slot n 1 is full, then the final depth after adding x may
6 1320 h.-j. boehm, r. atkinson and m. plass be n 1, but the resulting length is guaranteed to be at least F n+1, again guaranteeing balance. Subsequent concatenations (if any) involve concatenating two balanced ropes with lengths at least F m and F m 1 and producing a rope of depth m 1, which must again be balanced. Figure 2 shows this algorithm applied to a representation of abcdef. We have shown only slots 2,..,5, which correspond to the length intervals [1,2), [2,3), [3,5), and [5,8), and maximum depths 0, 1, 2, and 3, respectively. Note that the original was already balanced by our definition, as is likely to be the case for small examples. The above argument almost applies when we add a balanced tree b instead of a leaf to the sequence. We may introduce one additional tree level immediately above the insertion point for b, adding one to the depth of the final tree. In practice we insert already balanced trees as a unit, and thus avoid rebuilding the entire tree in response to a rebalancing operation. The final step in balancing a rope is to concatenate the sequence of ropes in order of increasing size. The resulting rope will not be balanced in the above sense, but its depth will exceed the desired value by at most 2. One additional root node may be introduced by the final concatenation. (Indeed, this is necessary. Consider concatenating a small leaf to a large balanced tree to another small leaf. We must add 2 to the depth of the resulting tree unless we re-examine the balanced tree. Note that only trees that are balanced by our original strict definition are not re-examined.) Many variations of this approach are possible. Our balance condition was expressed in terms of length, and our algorithm tends to move long flat ropes close to the root. One could also rebalance purely in terms of node count. C CORDS We implemented a version of the above as a C library. Since this implementation is lighter-weight than Cedar ropes, and heavier than C strings, we dubbed the resulting objects cords. Figure 2. Balancing abcdef
7 ropes: an alternative to strings 1321 The C implementation operates under certain constraints. The compiler dictates that a string constant is represented as a pointer to a NUL-terminated contiguous array of characters. For our package to be practical, C string constants must double as cord constants, whenever possible. Hence cords are also declared to be character pointers ( const char* to be exact), as are C strings, but are actually represented as either a NULL pointer, denoting the empty cord, or in one of the three ways shown in Figure 3. The first is a pointer to a non-empty C string, the second is essentially a pointer to a function closure for computing the ith character in the cord, and the third a pointer to a concatenation node. Concatenation nodes contain a one byte depth field, which is guaranteed to be sufficient, given the word length and balancing constraint. A one byte length of left child field is included, and eliminates nearly all calls to compute the length of C strings during cord traversals. A zero value in this field indicates a long left child. Cords are balanced exactly as described above. The substring operation may operate lazily and introduce a special variant of a closure node whose environment (pointed to by the client data field) contains a pointer to a (flat) cord, and a starting position within that cord. Substring operations on long flat cords do not copy characters. This special variant is recognized by the substring operation, so that nested substring operations do not result in nested substring nodes. This design has several benefits: Figure 3. Cord representation variants
8 1322 h.-j. boehm, r. atkinson and m. plass 1. String constants (or other non-empty C strings) may be passed directly to procedures expecting cords. Unfortunately, empty C strings must be converted to a NULL pointer. Erroneous uses of empty C strings could nearly always be cleanly detected, at minimal cost, in a debugging version of the library. 2. Unlike C strings, NUL characters may be embedded inside cords using the closure variant. 3. Concatenation and closure nodes are small. 4. The lengths of non-flat cords may be cheaply computed. Lengths of C strings at leaves may often be cheaply computed from the context in which they appear. (For example, the substring operation can usually do so.) We use the concatenation optimizations described above. Ropes are balanced either in response to an explicit call, or when the depth of a rope exceeds a threshold larger than the depth of any balanced rope. Since C does not provide function closures directly, it is clumsy to write client code that invokes an iterator function to traverse a string, tempting programmers to use the significantly slower fetch operation instead. (The recursive version of this operation is even slower than one might think on register window machines.) We sidestep this issue by introducing a cord position abstraction. Abstractly, this is a pair consisting of a cord, and a character index in the cord. Concretely, a cord position is represented by these, plus the path from the root of the cord to the leaf containing the index, and some cached information about the current leaf. Cord positions provide fast operations for retrieving the current character, and advancing the position to the next (or previous) character. The implementation uses a recent version of the conservative garbage collector described in References 8 and 9, as does the current Cedar implementation. It is available by anonymous ftp, together with the garbage collector, and a toy text editor built on cords. 1 This editor maintains a complete edit history as simply a stack of cords, each cord representing the entire file contents. Performance is usually more than adequate, even on multi-megabyte files. Memory use is moderate, both since history entries share nearly all of their space, and because large files can be read lazily, and not kept in memory. This implementation is, however, not nearly as mature as the Cedar implementation. CEDAR ROPES Cedar ropes are explicitly supported by the language. The representation of normal flat ropes (leaves) coincides with that of a built-in flat string type text. String constants have the type rope or text, depending on context. Concatenation is implemented with the optimizations described above. Balancing is also similar to what is described above. In addition to the representation variants used for cords, a Cedar rope may be represented by a replacement node, denoting a lazy replacement of a substring of a rope by another rope. It is unclear that this variant is necessary, since it could also be represented by a concatenation with substrings. Instead of leaves containing user-defined functions, Cedar ropes may be represented by object nodes that contain member functions to perform several different operations, including fetching a specific character. (All of the operations other than fetch have defaults provided.) This makes such nodes a bit more expensive to
9 ropes: an alternative to strings 1323 manipulate, but makes certain operations (e.g. traversal and copying characters to a flat buffer) considerably cheaper. Cedar substring nodes are completely separate from function nodes, and must be treated distinctly. As a result, they can be, and are, more heavily used. The substring operation descends into the tree until it finds the smallest rope r that entirely contains the desired substring. It then returns a substring node that refers to r. Rope traversal is accomplished primarily with a mapping function that applies a user-defined function to each character. Since Cedar allows nested functions to be passed as arguments, this provides a much cleaner interface than in C. The vast majority of interfaces that deal with sequences of characters traffic in ropes. Rope nodes are the single most commonly occurring object in most Cedar heaps, both in terms of their number and their total size. Much of the Cedar environment is available as Reference 10. PERFORMANCE The Cedar system makes heavy use of ropes throughout. The text editor represents an unstructured text file as a single rope. The performance of the system is quite competitive. Similarly, the above-mentioned toy editor performs quite well, even on very large files. In order to give some more quantitative comparisons of the techniques we advocate with conventional string programming techniques, we measured operations likely to be common in either case. Figure 4 reports the cost of string concatenations in CPU microseconds on a Sun SPARCstation 2. We measured the cost of concatenating two strings or ropes of various lengths. The top three lines reflect the cost of non-destructive concatenation using the standard C library with several different memory allocators. The bottom two correspond to rope concatenation, again with slightly different allocation overhead. More detailed explanations of all the measurements are deferred to the appendix. Figure 5 gives the time required to build a single C cord or conventional C string a character at a time, using various common, though not necessarily good, programming techniques. These correspond roughly to the techniques that might be used when reading in a text file or a command line, and buiding an in-memory version of the string. The vertical axis measures the time required to build a string of the indicated length. Note that not all operations are strictly comparable in functionality. The lines labelled UNBUFFERED and BUFFERED were obtained using the standard C realloc and strcat functions to build up the string either 1 or 128 characters at a time. The line labelled SIMPLE builds up the string in place (which is fastest, but not always practical). GEOMETRIC does the same, but starts with a small buffer and repeatedly doubles it. The remaining two lines use the CORD package, either by naïvely concatenating individual characters to a string (CAT BUILD), or by using an interface explicitly designed for the purpose (BUFFERED CORD). Note that BUFFERED CORD provides essentially the same performance as GEOMETRIC, and that CAT BUILD might still be tolerable for 100,000 character strings, where UNBUFFERED is completely unacceptable. Finally, Figure 6 gives the time required to completely traverse a C style string or cord of a given length. Times are again given per string traversal. The top four
10 1324 h.-j. boehm, r. atkinson and m. plass Figure 4. Concatenation time lines represent cord traversals, with varying programming sophistication. The bottom line represents a simple C traversal of a contiguous string of the same length. PREVIOUS WORK Many imperative programming languages have recognized the desirability of an immutable string type. The earliest language with immutable strings that we could find was SNOBOL, 11,12 followed by BASIC and XPL. SNOBOL implementations included flat immutable strings, together with a fast substring operation, and provisions for fast concatenation in special cases. The same is true of SAIL 13 and a number of other later language designs such as CLU, 14 Icon 15 and standard ML. The CLU design directly inspired Cedar ropes. But all implementations of which we are aware use flat representations, and hence cannot, for example, efficiently insert a character into the middle of a 100,000 character string. Linked string representations are considered in Reference 16. However, its author considers only linearly linked representations designed for fast in-place updates. Nondestructive concatenation and substring operations perform poorly on these representations. Several authors have discussed general techniques for efficient implementations of immutable data structures. Most of these rely on the use of balanced tree structures, and copying of modified nodes, as we do. Probably the closest to our work is
11 ropes: an alternative to strings 1325 Figure 5. Build time Reference 17, which discusses non-destructive operations on linear lists using AVL DAGs. The string case is not specifically discussed (though an editor application is also used). Our data structure is quite different from that of Reference 17 to accommodate fast concatenation, the small list elements (characters), lazily evaluated sublists, and the need for proper integration with string constants. A more sophisticated implementation technique for immutable data structures is described in Reference 18. That approach could be used, for example, to implement ropes with O(1) space cost for character insertion and deletion, even when the original rope is retained. However their approach again appears to require locking. The idea of representing a string as a tree of concatenations has been rediscovered multiple times, particularly in the context of attribute grammars (cf. Reference 5 or Rodney Farrow s Linguist system). Here a fast concatenation operation is often sufficient. We do not know of other published generalizations to a comprehensive collection of string operations. Cedar Ropes themselves have evolved since They are mentioned in passing, but not described, in References 19 and 20. References 21 and 22 each contain a one paragraph description of ropes, with no implementation details (some of which have changed since then). Reference 21 also discusses some applications of ropes. Variations of ropes have also appeared in DEC SRC programming environments. Modula-2+ provided both an interface and implementation similar to Cedar ropes. Modula 3 23 provides the interfaces, but the current implementation uses a flat
12 1326 h.-j. boehm, r. atkinson and m. plass Figure 6. Traversal time representation. (Though we have not done a thorough study, this choice appears to at least double the heap space requirements of one of the Modula-3 programs we did examine.) CONCLUSIONS We have argued that it is important to provide an immutable character string type that provides a cheap concatenation operation, and scales correctly to long strings, so that modules with string inputs can be truly reusable. It is important that programming languages either provide this facility or can be easily extended to provide it. The Cedar language supports it explicitly. It is possible to add it to C as a library, with some small further loss of type safety. This is much more than compensated for by the elimination of subscript errors resulting from needless lowlevel string manipulation. It is not clear whether the implementation we suggested above is in any sense optimal. However, it performs sufficiently well for our purposes, and sufficiently well that for most purposes it is preferred over traditional flat string representations. Our experience has been that it results in software that is noticeably more robust, particularly in that it scales correctly to unexpectedly large inputs.
13 ropes: an alternative to strings 1327 acknowledgements Many other members of PARC CSL have contributed to the Cedar Rope package. Dan Swinehart and one of the referees helped us track down the history of immutable strings. Both anonymous referees provided useful suggestions on an earlier draft of this paper. APPENDIX All measurements in Figures 4, 5, and 6 are in user mode CPU microseconds on a SPARCstation 2 running running SunOS We used version 4.1 of the package in Reference 1. The machine had enough memory (64 MB) that paging was not an issue. All programs were compiled with gcc and statically linked. Garbage collection times are included. The tests were run for enough iterations in the same heap to force several collections. Though the measurements are quite repeatable, they should be taken as rough values, since they depend on many parameters not discussed here. (For instance, the pointers to the strings were kept in statically-allocated global variables.) Figure 4 C CONCAT/GC Non-destructively concatenate a string to itself, using two strlen calls, an allocation, and two memcpy calls. This uses version 4.1 of our conservative garbage collector in its default (more space- than time-efficient) configuation. (The contiguous strings of length 200,000 were allocated with interior pointer recognition disabled to avoid anomalous behavior. See Reference 9 for a discussion of why this is desirable.) C CONCAT/BIG HEAP As above, but the heap was expanded by 4 MB at start-up. This significantly reduces garbage collection overhead. C CONCAT/SUN MALLOC As above, but uses the SunOS default malloc. Not that this actually performs slightly worse than even C CONCAT/GC for short strings, but outperforms the garbage collected versions for long strings (which force more frequent collection). CORD CONCAT Concatenate a cord to itself. Uses the garbage collector in default configuration. The cord was built as in BUFFERED CORD below. This matters only in that the cord is structured, and hence has an easily available length, except in the length 10 and 100 cases. The time per operation is basically constant, except that short strings require calls to strlen, and that long strings force a large heap, which tends to reduce GC overhead.
14 1328 h.-j. boehm, r. atkinson and m. plass CORD CONCAT/BIG Same as CORD CONCAT, except that the heap was expanded by 4 MB at start-up. Figure 5 All measurements were performed with our garbage collecting allocator. Our version of C s realloc explicitly deallocates memory; no other storage was explicitly deallocated. UNBUFFERED Build up a C string by initially allocating a single byte, and then repeatedly reallocating the buffer and adding the new character to the end with the C strcat function. Note that this copies the string only when realloc copies. (The realloc implementation copies at geometrically increasing lengths for small strings, and whenever the new object requires an additional page for large strings.) Every character involves a traversal of the first string. (This is a highly suboptimal algorithm, which unfortunately appears to be used occasionally.) BUFFERED Build up a C string by initially allocating a single byte, putting new characters in a buffer, and destructively appending the buffer to the strings when it is full. Append is implemented using C s realloc and strcat. The buffer size is 128 bytes. CAT BUILD We build a cord. A cord consisting of a single character is repeatedly concatenated to the cord. (This is usually an amateur programming technique, roughly comparable to UNBUFFERED. It does have the advantage that nothing is being destructively updated. Any prefix can be safely saved with a pointer copy.) BUFFERED CORD Similar to BUFFERED, but each time the buffer fills, it is concatenated to the cord. This uses routines provided by the cord implementation for this purpose. The buffer size is again 128. The resulting cord is explicitly balanced. The interface is similar to Modula-3 text writers. 23 The implementation is tuned for short strings. GEOMETRIC The space allocated to the string is grown by factors of 2, starting at 1. Strcat is not used, string length is not recomputed. SIMPLE Build up a C string by preallocating a sufficiently large buffer and filling it in. (A commonly used technique. Fails for unexpectedly long strings.)
15 ropes: an alternative to strings 1329 Figure 6 The traversal function computes the exclusive-or of all characters in the string. Thus the compiler is prevented from optimizing out major parts of the traversal. CORD TRAV Traverse a cord built by CONCAT, using the cord position primitives described above. With the help of some macros provided by the cord package, the traversal code looks very similar to what is needed for traversing a traditional C string. B. CORD TRAV Same as CORD TRAV, but uses the cord from BUFFERED CORD. The cord is more balanced with larger leaves. F. CORD TRAV Same as CORD TRAV, but does not use the cord position primitives. Instead it explicitly invokes an iterator function. The iterator function is passed a function that examines an individual character. It can also be optionally passed a second function that will accept longer substrings (as C strings) and process more than one character at a time. In this case such a function was also provided. This takes about 15 more lines of code than CORD TRAV. (This code would have to be repeated for each type of string traversal.) B.F. CORD TRAV Same as F. CORD TRAV, but uses the cord from BUFFERED CORD. This represents the best case for a cord traversal. C TRAVERSE Traverse a C string using explicit inline array subscripting. The C string pointer was stored in a global, but the resulting load was optimized out by the compiler. REFERENCES 1. The garbage collector and cord package can be retrieved from ftp://parcftp.xerox.com/pub/gc/gc.tar.z. A brief description can be found in ftp://parcftp.xerox.com/pub/gc/gc.html. 2. Eugene H. Spafford, Crisis and aftermath, in Special Section on the Internet Worm, Communications of the ACM 32, (6), , (1989). 3. D. Knuth, The Art of Computer Programming, Vol. 3, Searching and Sorting, Addision-Wesley, Samuel W. Bent, Daniel D. Sleator and Robert E. Tarjan, Biased 2-3 trees, Proceedings of the 21st Annual Symposium on Foundations of Computer Science, IEEE, 1980, pp H. Boehm and W. Zwaenepoel, Parallel attribute grammar evaluation, Proceedings of the 7th International Conference on Distributed Computing Systems, September 1987, pp Robert R. Tarjan, Data Structures and Network Algorithms, SIAM, D. Sleator and R. Tarjan, Self-adjusting binary trees, Proceedings, Fifteenth Annual ACM Symposium on Theory of Computing, 1983, pp Hans-J. Boehm and Mark Weiser, Garbage collection in an uncooperative environment, Software Practice and Experience 18, (1988).
16 1330 h.-j. boehm, r. atkinson and m. plass 9. Hans-J. Boehm, Space efficient conservative garbage collection, Proceedings of the ACM SIGPLAN 93 Conference on Programming Language Design and Implementation, SIGPLAN Notices 28, (6), (1993). 10. C. Hauser, C. Jacobi, M. Theimer, B. Welch and M. Weiser, Using threads in interactive systems: a case study, Xerox PARC Technical Report CSL CD. This is a CD-ROM containing both a paper and a Cedar system that can be run under SunOS. Source code is included for much of the system, including the Rope package. 11. D. Farber, R. E. Griswold and I. P. Polansky, SNOBOL, a string manipulation language, Journal of the Association for Computing Machinery, 11, (1), (1964). 12. R. E. Griswold, J. F. Poage and I. P. Polonsky, The SNOBOL4 Programming Language, Second Edition, Prentice-Hall, Kurt A. VanLehn (ed.), SAIL user manual, Report STAN-CS , Stanford Computer Science Department, July B. Liskov, R. Atkinson, T. Bloom, E. Moss, J. C. Schaffert, R. Scheiffler and A. Snyder, CLU Reference Manual, Springer, R. E. Griswold and M. T. Griswold, The Implementation of the Icon Programming Language, Princeton University Press, Stuart E. Madnick, String processing techniques, Communications of the ACM, 10, (7), , (1967). 17. Eugene W. Myers, Efficient applicative data types, Conference Record of the Eleventh Annual ACM Symposium on Principles of Programming Languages, January 1984, pp D. Driscoll, N. Sarnak, D. Sleator and R. Tarjan, Making data structures persistent, JCSS, 38, (1), (1989). 19. Butler W. Lampson, A description of the Cedar programming language: a Cedar language reference manual, Xerox PARC Report CSL 83 15, December 1983 (out of print). 20. D. Swinehart, P. Zellweger and R. Hagmann, The structure of Cedar, Proceedings of the ACM SIGPLAN 85 Symposium on Language Issues in Programming Environments, SIGPLAN Notices, 20, (7), (1985). 21. D. Swinehart, P. Zellweger, R. Beach and R. Hagmann, A structural view of the Cedar programming environment, Xerox PARC Report CSL 86.1, June W. Teitelman, A tour through Cedar, IEEE Software, April 1984, pp Greg Nelson (ed.), Systems Programming in Modula-3, Prentice Hall, 1991.
Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents
SOFTWARE PRACTICE AND EXPERIENCE, VOL. 23(4), 369 382 (APRIL 1993) An Evaluation of Self-adjusting Binary Search Tree Techniques jim bell and gopal gupta Department of Computer Science, James Cook University,
Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 02 Lecture No. # 05 Run-time Environments-Part 3 and Local Optimizations
B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:
Physical Data Organization Database design using logical model of the database - appropriate level for users to focus on - user independence from implementation details Performance - other major factor
http://www.devx.com Printed from http://www.devx.com/java/article/21977/1954 Garbage Collection in the Java HotSpot Virtual Machine Gain a better understanding of how garbage collection in the Java HotSpot
A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function
6.854 Advanced Algorithms Lecture 2: September 9, 2005 Scribes: Sommer Gentry, Eddie Kohler Lecturer: David Karger Persistent Data Structures 2.1 Introduction and motivation So far, we ve seen only ephemeral
Introduction to Operating Systems File System Implementation II Performance, Recovery, Network File System John Franco Electrical Engineering and Computing Systems University of Cincinnati Review Block
Programming Languages Memory Allocation & Garbage Collection CSCI.GA-2110-003 Fall 2011 Dynamic memory management For most languages, the amount of memory used by a program cannot be determined at compile
Dynamic Storage Allocation CS 44 Operating Systems Fall 5 Presented By Vibha Prasad Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need
CS61: Systems Programming and Machine Organization Harvard University, Fall 2009 Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc() Prof. Matt Welsh October 6, 2009 Topics for today Dynamic
inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each
By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First
B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:
Architecture of software systems Course 10: Data structures, memory management, garbage collector, references David Šišlák firstname.lastname@example.org Data structures» primitives: boolean, byte, char, int,
Data storage Tree indexes Rasmus Pagh February 7 lecture 1 Access paths For many database queries and updates, only a small fraction of the data needs to be accessed. Extreme examples are looking or updating
PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions
Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science email@example.com Names, Bindings, and Scopes A name is a symbolic identifier used
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
A Sorting based Algorithm for the Construction of Balanced Search Tree Automatically for smaller elements and with minimum of one Rotation for Greater Elements from BST S. Muthusundari Research Scholar,
Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture
THE CERN/SL XDATAVIEWER: AN INTERACTIVE GRAPHICAL TOOL FOR DATA VISUALIZATION AND EDITING Abstract G. Morpurgo, CERN As a result of many years of successive refinements, the CERN/SL Xdataviewer tool has
Validating Java for Safety-Critical Applications Jean-Marie Dautelle * Raytheon Company, Marlborough, MA, 01752 With the real-time extensions, Java can now be used for safety critical systems. It is therefore
CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages Corky Cartwright Swarat Chaudhuri November 30, 20111 Overview I In OO languages, data values (except for designated non-oo
Storage Management for Files of Dynamic Records Justin Zobel Department of Computer Science, RMIT, GPO Box 2476V, Melbourne 3001, Australia. firstname.lastname@example.org Alistair Moffat Department of Computer Science
The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints
CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical
Operating Systems CSE 410, Spring 2004 File Management Stephen Wagner Michigan State University File Management File management system has traditionally been considered part of the operating system. Applications
Analysis of Compression Algorithms for Program Data Matthew Simpson, Clemson University with Dr. Rajeev Barua and Surupa Biswas, University of Maryland 12 August 3 Abstract Insufficient available memory
+ Raima Database Manager Version 14.0 In-memory Database Engine By Jeffrey R. Parsons, Senior Engineer January 2016 Abstract Raima Database Manager (RDM) v14.0 contains an all new data storage engine optimized
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
File Systems Management and Examples Today! Efficiency, performance, recovery! Examples Next! Distributed systems Disk space management! Once decided to store a file as sequence of blocks What s the size
Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary
We SOLVE COMPLEX PROBLEMS of DATA MODELING and DEVELOP TOOLS and solutions to let business perform best through data analysis Whitepaper: performance of SqlBulkCopy This whitepaper provides an analysis
Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition Memory Management: Early Systems Memory is second only to processes in importance (and in intensity) with which
Overview Memory Management Stack: Data on stack (local variables on activation records) have lifetime that coincides with the life of a procedure call. Memory for stack data is allocated on entry to procedures......
CS 2SC3 and SE 2S03 Fall 2009 05 Case Study: C Programming Language William M. Farmer Department of Computing and Software McMaster University 18 November 2009 The C Programming Language Developed by Dennis
Memory management in C: The heap and the stack Leo Ferres Department of Computer Science Universidad de Concepción email@example.com October 7, 2010 1 Introduction When a program is loaded into memory, it
Presentation Layer The presentation layer is concerned with preserving the meaning of information sent across a network. The presentation layer may represent (encode) the data in various ways (e.g., data
Free University of Bolzano Database 2. Lecture I, 2003/2004 A.Artale (1) Database 2 Lecture I Alessandro Artale Faculty of Computer Science Free University of Bolzano Room: 221 firstname.lastname@example.org http://www.inf.unibz.it/
Last Class: Introduction to Operating Systems User apps OS Virtual machine interface hardware physical machine interface An operating system is the interface between the user and the architecture. History
University of Dayton Department of Computer Science Undergraduate Programs Assessment Plan DRAFT September 14, 2011 Department Mission The Department of Computer Science in the College of Arts and Sciences
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).
Storage Structures Unit 4.3 Unit 4.3 - Storage Structures 1 The Physical Store Storage Capacity Medium Transfer Rate Seek Time Main Memory 800 MB/s 500 MB Instant Hard Drive 10 MB/s 120 GB 10 ms CD-ROM
Interpreters and virtual machines Michel Schinz 2007 03 23 Interpreters Interpreters Why interpreters? An interpreter is a program that executes another program, represented as some kind of data-structure.
gprof A Call Graph Execution Profiler PSD:18-1 gprof: a Call Graph Execution Profiler 1 by Susan L. Graham Peter B. Kessler Marshall K. McKusick Computer Science Division Electrical Engineering and Computer
System Software Prof. Dr. H. Mössenböck 1. Memory Management 2. Garbage Collection 3. Linkers and Loaders 4. Debuggers 5. Text Editors Marks obtained by end-term exam http://ssw.jku.at/misc/ssw/ 1. Memory
Strings in C : Overview : String data type is not supported in C Programming. String is essentially a collection of characters to form particular word. String is useful whenever we accept name of the person,
Lecture 1: Data Storage & Index R&G Chapter 8-11 Concurrency control Query Execution and Optimization Relational Operators File & Access Methods Buffer Management Disk Space Management Recovery Manager
MapReduce MapReduce and SQL Injections CS 3200 Final Lecture Jeffrey Dean and Sanjay Ghemawat. MapReduce: Simplified Data Processing on Large Clusters. OSDI'04: Sixth Symposium on Operating System Design
CSCI E 98: Managed Environments for the Execution of Programs Draft Syllabus Instructor Phil McGachey, PhD Class Time: Mondays beginning Sept. 8, 5:30-7:30 pm Location: 1 Story Street, Room 304. Office
Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson
1 The Java Virtual Machine About the Spec Format This document describes the Java virtual machine and the instruction set. In this introduction, each component of the machine is briefly described. This
A Performance and Distributed Performance Benchmark of InfiniteGraph and a Leading Open Source Graph Database Using Synthetic Data Objectivity, Inc. 640 West California Ave. Suite 240 Sunnyvale, CA 94086
Advanced C Programming Memory Management II (malloc, free, alloca, obstacks, garbage collection) Sebastian Hack email@example.com Christoph Weidenbach firstname.lastname@example.org 16.12.2008 saarland university
SkyRecon Cryptographic Module (SCM) FIPS 140-2 Documentation: Security Policy Abstract This document specifies the security policy for the SkyRecon Cryptographic Module (SCM) as described in FIPS PUB 140-2.
Record Storage and Primary File Organization 1 C H A P T E R 4 Contents Introduction Secondary Storage Devices Buffering of Blocks Placing File Records on Disk Operations on Files Files of Unordered Records
CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes
Lecture 8 Balanced search trees 8.1 Overview In this lecture we discuss search trees as a method for storing data in a way that supports fast insert, lookup, and delete operations. (Data structures handling
Topics COS 318: Operating Systems File Layout and Directories File system structure Disk allocation and i-nodes Directory and link implementations Physical layout for performance 2 File System Components
Operating Systems Memory Management Lecture 9 Michael O Boyle 1 Chapter 8: Memory Management Background Logical/Virtual Address Space vs Physical Address Space Swapping Contiguous Memory Allocation Segmentation
INTRODUCTION 1 Programming languages have common concepts that are seen in all languages This course will discuss and illustrate these common concepts: Syntax Names Types Semantics Memory Management We
COMP 242 Class Notes Section 6: File Management 1 File Management We shall now examine how an operating system provides file management. We shall define a file to be a collection of permanent data with
Problem Given a large collection of records, Indexing with B-trees find similar/interesting things, i.e., allow fast, approximate queries Anastassia Ailamaki http://www.cs.cmu.edu/~natassa 2 Indexing Primary
6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.
Fast Sequential Summation Algorithms Using Augmented Data Structures Vadim Stadnik email@example.com Abstract This paper provides an introduction to the design of augmented data structures that offer
COS 318: Operating Systems Snapshot and NFS Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall10/cos318/ Topics Revisit Transactions and Logging
CSL373: Lecture 14 User level memory management Today: dynamic memory allocation Almost every useful program uses dynamic allocation: gives wonderful functionality benefits don t have to statically specify
Extreme Performance with Java QCon NYC - June 2012 Charlie Hunt Architect, Performance Engineering Salesforce.com sfdc_ppt_corp_template_01_01_2012.ppt In a Nutshell What you need to know about a modern
Storage Allocation in Typed Languages Butler W. Lampson Xerox Corporation Palo Alto Research Center Appeared in Proc. 5th Ann. III Conf: Implementation and Design of Algorithmic Languages, Guidel, France,
Overview of Presentation responsibilities of a memory manager user view of memory management memory management strategies, algorithms fixed partitions, variable partitions algorithms, fragmentation, coalescing