How to store a Tree Structure in Memory
1 posts in topic
Flat View  Flat View

Posted By:   Neo_Ruan
Posted On:   Wednesday, January 9, 2002 07:23 PM

I wanted to show a Org Chart on web page. Recursion is used for constructing.Based on B/S architecture,(get Org from DataBase)this is not a effective way!! How can I store a tree structure(Org object are stored as TreeNodes) in memory for recursion??? Thanks!

Re: How to store a Tree Structure in Memory

Posted By:   Neo_Ruan  
Posted On:   Thursday, January 10, 2002 12:44 AM

My English is too poor! So I posted the interfaces blow.

I used these interface to construct a org tree(which will displyed in browser ),but it's
efficiency is low. (recursion)Because the org infor. are stored in database(thounds of
orgs are stored).(I think this is the bottleneck)

Now I want to store the tree structure in memeory! Then jsp page only needs to build the tree
from memory!Needn't make a DbConnection every time. A timer will updated tree org(in memory)

So I want to use a N dimensions array to store the data (N is the number of orgs)
but I don't konw how to make a compositor for sorting!

after sorting .look at the matrix I poster blow(eg.)

Matrix:(a,b,c,d are orgs 1 mean's is parents 0 means not, this is a Sparse Set huh? ^_^ )

  a b c d

a 0 0 0 0

b 1 0 0 0

c 1 0 0 0

d 0 1 0 0

Org tree:



  b  c



so O(n(n-1)/2)


1)How to sort orgs?

2)Any good suggestion is wanted!



public interface IOrg { //entity class

public String getName(); //get Org Name

public String getId(); //get Org Id

public String getLevel(); //get Org Level (as String)

public String getParentId(); //get parent org Id

public String getDescription(); //get the description

public boolean isActive(); //is Org active



Org Factory


import java.util.*;

* Description of the Interface
*@author Neo ymruan
public interface IOrgFactory {

public IOrg getOrgById(String orgId);

public IOrg getOrgByObjId(String objId);

public Enumeration getManagers(String orgId);

public Enumeration getManagers(IOrg org);

public Enumeration getEmployees(String orgId);

public Enumeration getEmployees(IOrg org);

public Enumeration getOrgsByLevel(String level);

public Enumeration getAllOrgs();

public Enumeration getOrgsLikeName(String name);

public IOrg getParentOrg(IOrg org);

public IOrg getRootOrg(); //get Root Org

public Enumeration getChildOrgs(IOrg org); //get Ogg's children

public boolean hasSubOrgs(IOrg org); // is leaf

public boolean hasActiveSubOrgs(IOrg org);

public boolean isInOrg(String orgId, String empId);

public boolean hasEmployees(IOrg org);

About | Sitemap | Contact