Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using IndexSet to store policy in assertion #47

Merged
merged 3 commits into from
Jan 24, 2020

Conversation

GopherJ
Copy link
Member

@GopherJ GopherJ commented Jan 21, 2020

Previously we are using sort_unstable + dedup to avoid adding a policy the second time, but the sort operation is expensive, so I made this PR which stores policies in HashSet, in rust there is no problem to compare two arrays.

That'll probably make it more efficient.

@GopherJ
Copy link
Member Author

GopherJ commented Jan 21, 2020

The disadvantage is that HashSet doesn't guarantee the order of elements, so when we run get_policy it will probably gives differents results:

1st run:

[["alice", "/user/profile", "read"], ["bob", "/user/profile", "write"]]

2nd run:

[["bob", "/user/profile", "write"], ["alice", "/user/profile", "read"]]

But from an user's prospective, I think it's ok to have different orders.

@codecov
Copy link

codecov bot commented Jan 21, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@c0fbedb). Click here to learn what that means.
The diff coverage is 87.87%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #47   +/-   ##
=========================================
  Coverage          ?   85.89%           
=========================================
  Files             ?       12           
  Lines             ?     1992           
  Branches          ?        0           
=========================================
  Hits              ?     1711           
  Misses            ?      281           
  Partials          ?        0
Impacted Files Coverage Δ
src/enforcer.rs 85.34% <100%> (ø)
src/adapter/file_adapter.rs 45.65% <50%> (ø)
src/internal_api.rs 84% <80%> (ø)
src/management_api.rs 88.44% <80.76%> (ø)
src/rbac_api.rs 83.24% <90.21%> (ø)
src/rbac/default_role_manager.rs 93.07% <91.89%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0fbedb...f91d57f. Read the comment docs.

@GopherJ
Copy link
Member Author

GopherJ commented Jan 21, 2020

@hsluoyz How do you think?

@hsluoyz
Copy link
Member

hsluoyz commented Jan 21, 2020

@GopherJ will Golang Casbin keep the order?

@GopherJ
Copy link
Member Author

GopherJ commented Jan 21, 2020

@hsluoyz Yes it will keep the result's order. So I'm not sure how do we handle this in rust, sort_unstable + dedup can solve the problem but it's really expensive operation: nlogn + n probably.

@hsluoyz
Copy link
Member

hsluoyz commented Jan 22, 2020

@GopherJ can we have the same behavior as Golang Casbin?

@GopherJ
Copy link
Member Author

GopherJ commented Jan 24, 2020

@hsluoyz Yes, I just changed HashSet to IndexSet which guarantee the order.

@GopherJ GopherJ changed the title using HashSet to store policy in assertion using IndexSet to store policy in assertion Jan 24, 2020
@GopherJ GopherJ force-pushed the improve/replace-vec-by-hashset branch from 2f21983 to f91d57f Compare January 24, 2020 09:22
@hsluoyz
Copy link
Member

hsluoyz commented Jan 24, 2020

lgtm

@hsluoyz hsluoyz merged commit db25089 into casbin:master Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants