1

I want to represent user in some hierarchy for fast search,

I am planning something like below

<root>:<parent>:<group>:<user> 

1:123:154:11 
1:123:154:12
1:123:152:13
1:124:159:15
1:123:153:14
2:125:150:10
2:124:149:19 

function template

isValid(pid, myid){

} 

Where, this function first myId will be any next level ID and, pid will be imediate partentID .

or both will be my IDs only .

//myid belongs to proper pid
isValid(154,11) => true 


//myid belongs to proper pid
isValid(154,13) => false 

//myid comes under proper pid 
isValid(123,154) =>  true 

isValid(154,123) =>  false 

//Here I gave root ID as pid,so still valid 
isValid(1,154) =>  true 


isValid(154,12) =>  true 


isValid(150,19) =>  false 

    **this is major problem when user skips 
    when 123 gives his pratner ID and and trying compare with 159 it should return false 
    1:123:152:13
    1:124:159:15
    isValid(1,159) =>  false  // This is becoming conflicts with my way of hierarchy define

My user level also grows so I want to know given a hierarchy check for user id and pid must be valid in hierarchy ?

indra
  • 832
  • 4
  • 17
  • 33
  • https://stackoverflow.com/a/38701519/5962802 – IVO GELOV Mar 22 '20 at 20:15
  • It seems that `isValid(1,159)` should return `true`, but that does not mean that `123` is on the path. That's another check, maybe `isValid(1,159) && isValid(123,159)`. Here, `isValid` seems to mean: does my ancestor have any descendant matching this id? That's not specific enough. – jferard Mar 23 '20 at 10:03

0 Answers0