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


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

Re: searching a tree of objects

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: searching a tree of objects
Date Tue, 8 Dec 2015 19:22:18 -0000 (UTC)
Organization A noiseless patient Spider
Lines 45
Message-ID <n47ala$asp$1@dont-email.me> (permalink)
References <a8beac79-4ac8-4abd-b680-ab4a3112dd51@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Tue, 8 Dec 2015 19:22:18 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="11161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+x48Wf6/I5cEE3o0V8Qrc8ALmfmayKRU="
User-Agent Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
Cancel-Lock sha1:BRZQATVe6ovpk+yJZuP9e9TFZcY=
Xref csiph.com comp.lang.java.programmer:33317

Show key headers only | 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