annotate .svn/pristine/e6/e6c6e613ff0d2c3cc9757a8612a421623bc71bcc.svn-base @ 1613:90bed4e10cc8 deploy

Download file link
author Chris Cannam
date Wed, 30 Aug 2017 17:24:37 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1
Chris@909 2 __ _ _
Chris@909 3 /__\_ _| |__ _ _| |_ _ __ ___ ___
Chris@909 4 / \// | | | '_ \| | | | __| '__/ _ \/ _ \
Chris@909 5 / _ \ |_| | |_) | |_| | |_| | | __/ __/
Chris@909 6 \/ \_/\__,_|_.__/ \__, |\__|_| \___|\___|
Chris@909 7 |___/
Chris@909 8
Chris@909 9 (c) 2006, 2007 Anupam Sengupta
Chris@909 10 http://rubytree.rubyforge.org
Chris@909 11
Chris@909 12 Rubytree is a simple implementation of the generic Tree data structure. This
Chris@909 13 implementation is node-centric, where the individual nodes on the tree are the
Chris@909 14 primary objects and drive the structure.
Chris@909 15
Chris@909 16 == INSTALL:
Chris@909 17
Chris@909 18 Rubytree is an open source project and is hosted at:
Chris@909 19
Chris@909 20 http://rubytree.rubyforge.org
Chris@909 21
Chris@909 22 Rubytree can be downloaded as a Rubygem or as a tar/zip file from:
Chris@909 23
Chris@909 24 http://rubyforge.org/frs/?group_id=1215&release_id=8817
Chris@909 25
Chris@909 26 The file-name is one of:
Chris@909 27
Chris@909 28 rubytree-<VERSION>.gem - The Rubygem
Chris@909 29 rubytree-<VERSION>.tgz - GZipped source files
Chris@909 30 rubytree-<VERSION>.zip - Zipped source files
Chris@909 31
Chris@909 32 Download the appropriate file-type for your system.
Chris@909 33
Chris@909 34 It is recommended to install Rubytree as a Ruby Gem, as this is an easy way to
Chris@909 35 keep the version updated, and keep multiple versions of the library available on
Chris@909 36 your system.
Chris@909 37
Chris@909 38 === Installing the Gem
Chris@909 39
Chris@909 40 To Install the Gem, from a Terminal/CLI command prompt, issue the command:
Chris@909 41
Chris@909 42 gem install rubytree
Chris@909 43
Chris@909 44 This should install the gem file for Rubytree. Note that you may need to be a
Chris@909 45 super-user (root) to successfully install the gem.
Chris@909 46
Chris@909 47 === Installing from the tgz/zip file
Chris@909 48
Chris@909 49 Extract the archive file (tgz or zip) and run the following command from the
Chris@909 50 top-level source directory:
Chris@909 51
Chris@909 52 ruby ./setup.rb
Chris@909 53
Chris@909 54 You may need administrator/super-user privileges to complete the setup using
Chris@909 55 this method.
Chris@909 56
Chris@909 57 == DOCUMENTATION:
Chris@909 58
Chris@909 59 The primary class for this implementation is Tree::TreeNode. See the
Chris@909 60 class documentation for an usage example.
Chris@909 61
Chris@909 62 From a command line/terminal prompt, you can issue the following command to view
Chris@909 63 the text mode ri documentation:
Chris@909 64
Chris@909 65 ri Tree::TreeNode
Chris@909 66
Chris@909 67 Documentation on the web is available at:
Chris@909 68
Chris@909 69 http://rubytree.rubyforge.org/rdoc
Chris@909 70
Chris@909 71 == EXAMPLE:
Chris@909 72
Chris@909 73 The following code-snippet implements this tree structure:
Chris@909 74
Chris@909 75 +------------+
Chris@909 76 | ROOT |
Chris@909 77 +-----+------+
Chris@909 78 +-------------+------------+
Chris@909 79 | |
Chris@909 80 +-------+-------+ +-------+-------+
Chris@909 81 | CHILD 1 | | CHILD 2 |
Chris@909 82 +-------+-------+ +---------------+
Chris@909 83 |
Chris@909 84 |
Chris@909 85 +-------+-------+
Chris@909 86 | GRANDCHILD 1 |
Chris@909 87 +---------------+
Chris@909 88
Chris@909 89 require 'tree'
Chris@909 90
Chris@909 91 myTreeRoot = Tree::TreeNode.new("ROOT", "Root Content")
Chris@909 92
Chris@909 93 myTreeRoot << Tree::TreeNode.new("CHILD1", "Child1 Content") << Tree::TreeNode.new("GRANDCHILD1", "GrandChild1 Content")
Chris@909 94
Chris@909 95 myTreeRoot << Tree::TreeNode.new("CHILD2", "Child2 Content")
Chris@909 96
Chris@909 97 myTreeRoot.printTree
Chris@909 98
Chris@909 99 child1 = myTreeRoot["CHILD1"]
Chris@909 100
Chris@909 101 grandChild1 = myTreeRoot["CHILD1"]["GRANDCHILD1"]
Chris@909 102
Chris@909 103 siblingsOfChild1Array = child1.siblings
Chris@909 104
Chris@909 105 immediateChildrenArray = myTreeRoot.children
Chris@909 106
Chris@909 107 # Process all nodes
Chris@909 108
Chris@909 109 myTreeRoot.each { |node| node.content.reverse }
Chris@909 110
Chris@909 111 myTreeRoot.remove!(child1) # Remove the child
Chris@909 112
Chris@909 113 == LICENSE:
Chris@909 114
Chris@909 115 Rubytree is licensed under BSD license.
Chris@909 116
Chris@909 117 Copyright (c) 2006, 2007 Anupam Sengupta
Chris@909 118
Chris@909 119 All rights reserved.
Chris@909 120
Chris@909 121 Redistribution and use in source and binary forms, with or without modification,
Chris@909 122 are permitted provided that the following conditions are met:
Chris@909 123
Chris@909 124 - Redistributions of source code must retain the above copyright notice, this
Chris@909 125 list of conditions and the following disclaimer.
Chris@909 126
Chris@909 127 - Redistributions in binary form must reproduce the above copyright notice, this
Chris@909 128 list of conditions and the following disclaimer in the documentation and/or
Chris@909 129 other materials provided with the distribution.
Chris@909 130
Chris@909 131 - Neither the name of the organization nor the names of its contributors may
Chris@909 132 be used to endorse or promote products derived from this software without
Chris@909 133 specific prior written permission.
Chris@909 134
Chris@909 135 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@909 136 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@909 137 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Chris@909 138 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
Chris@909 139 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Chris@909 140 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Chris@909 141 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Chris@909 142 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Chris@909 143 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@909 144 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@909 145
Chris@909 146
Chris@909 147 (Document Revision: $Revision: 1.16 $ by $Author: anupamsg $)