Skip to content

Commit

Permalink
Fix ResultSet Intersect method (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Mar 21, 2024
1 parent 9ba5342 commit 2a10400
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/authz/query/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ func (rs *ResultSet) Union(other *ResultSet) *ResultSet {
}

func (rs *ResultSet) Intersect(other *ResultSet) *ResultSet {
resultSet := NewResultSet()
var iter *ResultSetNode
result := NewResultSet()
var a, b *ResultSet
if rs.Len() < other.Len() {
iter = rs.List()
a = rs
b = other
} else {
iter = other.List()
a = other
b = rs
}

for iter != nil {
if other.Has(iter.ObjectType, iter.ObjectId, iter.Relation) {
otherRes := other.Get(iter.ObjectType, iter.ObjectId, iter.Relation)
if !otherRes.IsImplicit {
resultSet.Add(otherRes.ObjectType, otherRes.ObjectId, otherRes.Relation, otherRes.Warrant, otherRes.IsImplicit)
for iter := a.List(); iter != nil; iter = iter.Next() {
if b.Has(iter.ObjectType, iter.ObjectId, iter.Relation) {
bRes := b.Get(iter.ObjectType, iter.ObjectId, iter.Relation)
if !bRes.IsImplicit {
result.Add(bRes.ObjectType, bRes.ObjectId, bRes.Relation, bRes.Warrant, bRes.IsImplicit)
} else {
resultSet.Add(iter.ObjectType, iter.ObjectId, iter.Relation, iter.Warrant, iter.IsImplicit)
result.Add(iter.ObjectType, iter.ObjectId, iter.Relation, iter.Warrant, iter.IsImplicit)
}
}

iter = iter.Next()
}

return resultSet
return result
}

func (rs *ResultSet) String() string {
Expand Down

0 comments on commit 2a10400

Please sign in to comment.