Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33317

Re: searching a tree of objects

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: searching a tree of objects
Date 2015-12-08 19:22 +0000
Organization A noiseless patient Spider
Message-ID <n47ala$asp$1@dont-email.me> (permalink)
References <a8beac79-4ac8-4abd-b680-ab4a3112dd51@googlegroups.com>

Show all headers | View raw


On Tue, 08 Dec 2015 10:29:24 -0800, mike wrote:

> Hi,
> 
> We have a tree of objects with root at the top.
> Now I want to search the tree for a specific node (object)
> search string will look like:
> 
> name=<index>,name2=<index2>,name3=<index3>
> 
> example could be:
> 
> RootType=1,Device=1,DdcDevice=1
> 
>                                 Rootype=1
>                                    |
>                               ----------- |          |
>                            Device=1   Equipment=1
>                               |
>             ---------------------------------------
>             |           |         |          |
>        DbcDevice=1  DbcDevice=2 DrpDevice=2 VrpDevice=1
> 
> In each object I have the information name=<index> in an attribute
> called identifier.
> 
> How can I use the search string and find the correct node that is
> DbcDevice=1 and return another attribute for this object.
> 
What is the purpose of your tree and what do you expect to return from 
searching it? 

If you expect to return a path to the target node, e.g 
"RootType,Device.RrpDevice" as well as and attribute of the target node 
content, then simply recursively walking the tree is your best bet.

OTOH, If all you want to do is directly access a node or the subtree 
beneath it, use a HashMap as a fast node index. Use a TreeMap if you need 
an ordered index of node names.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

searching a tree of objects mike <mikaelpetterson@hotmail.com> - 2015-12-08 10:29 -0800
  Re: searching a tree of objects Eric Douglas <e.d.programmer@gmail.com> - 2015-12-08 10:43 -0800
  Re: searching a tree of objects Martin Gregorie <martin@address-in-sig.invalid> - 2015-12-08 19:22 +0000
  Re: searching a tree of objects mike <mikaelpetterson@hotmail.com> - 2016-01-07 21:59 -0800
    Re: searching a tree of objects Eric Douglas <e.d.programmer@gmail.com> - 2016-01-08 13:35 -0800
    Re: searching a tree of objects Martin Gregorie <martin@address-in-sig.invalid> - 2016-01-08 12:13 +0000

csiph-web