Re: limitations of sequences, revisited
- Posted by David Cuny <dcuny at LANSET.COM> Dec 27, 2000
- 596 views
George Henry wrote: > No! And my "complaint" was that I cannot > use such techniques to MODIFY a value deeply > buried within the structure. I think the confusion stems from the fact that, in Euphoria, it's often trivial to embed all the data in the same structure. And it's often convenient to do just that. But for cases where this is problematic (like your example), you can trivially model the code as it is done in C by using indexes instead of pointers. For example, you could create the tree as an array of tuples: constant DATA = 1, LEFT = 2, RIGHT = 3 Instead of storing a subtree in the left and right nodes, store the index to the node. Here's a trivial example showing a binary tree for the data values "a", "b", "c" and "d": { { "b", 2, 3 }, { "a", 0, 0 }, { "c", 0, 4 }, { "d", 0, 0 } } Each node of the tree can be identified with a single index. Or you could choose to seperate the data from the structure. The following example is the same as the prior, but instead of placing the data in the structure, indexes to the data (which is placed in another structure) are used: -- structure { { 1, 2, 3 }, { 2, 0, 0 }, { 3, 0, 4 }, { 4, 0, 0 } } -- data { "b", "a", "c", "d" } Another option is to keep the embedded tree structure, but store the data in a seperate structure. The following example embeds a tree in each node, but stores the data in a seperate structure. Instead of storing the data in the tree, the first element of the tuple contains an index to the data: { index to data, left node, right node } -- the tree {1, {2, {}, {}}, {3, {}, {4, {}, {}}} } -- the data { "b", "a", "c", "d" } In any event, by either flattening the structure and using indexes, or storing data in a second sequence and referencing them with indexes, you can accomplish what you want without having to resort to pointers. I hope this helps! -- David Cuny