Algorithm 如何更好地表示用户层次结构以加快搜索速度
我想在一些层次结构中表示用户,以便快速搜索 我正在计划下面的事情Algorithm 如何更好地表示用户层次结构以加快搜索速度,algorithm,hierarchy,hierarchical-data,Algorithm,Hierarchy,Hierarchical Data,我想在一些层次结构中表示用户,以便快速搜索 我正在计划下面的事情 <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 其中,此函数的第一个myId将是任何下一级ID,pid将是imediate partentID 或者两者都是我的身份证 //myid
<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
其中,此函数的第一个myId将是任何下一级ID,pid将是imediate partentID
或者两者都是我的身份证
//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
我的用户级别也在增长,因此我想知道给定的用户id和pid的层次结构检查必须在层次结构中有效?似乎isValid(1159)
应该返回true
,但这并不意味着123
在路径上。这是另一个检查,可能isValid(1159)和&isValid(123159)
。这里,isValid
似乎意味着:我的祖先是否有与此id匹配的后代?这还不够具体。似乎isValid(1159)
应该返回true
,但这并不意味着123
在路径上。这是另一个检查,可能isValid(1159)和&isValid(123159)
。这里,isValid
似乎意味着:我的祖先是否有与此id匹配的后代?这还不够具体。
//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