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

Missing check in PatriciaTreeMap::leq implementation #1

Closed
arthaud opened this issue Aug 22, 2018 · 2 comments
Closed

Missing check in PatriciaTreeMap::leq implementation #1

arthaud opened this issue Aug 22, 2018 · 2 comments

Comments

@arthaud
Copy link
Contributor

arthaud commented Aug 22, 2018

Hello spartans (Salut Arnaud!),

I think there is a bug in the PatriciaTreeMap::leq() implementation.

If both trees are leaves, you should check if the keys are the same before comparing the values:

https://github.com/facebookincubator/SPARTA/blob/b1d453e871941b095e0297b6f8065e1230729309/include/PatriciaTreeMap.h#L500

Best regards

@arnaudvenet
Copy link
Contributor

Salut Maxime,

I can see that you still have the knack of finding subtle problems in Abstract Interpretation algorithms 🙂.

I'll go ahead and fix this.

Thanks!

@arnaudvenet
Copy link
Contributor

Fixed by commit 0228ec6e9c049d7782f195e3d407dde351255df6.

facebook-github-bot pushed a commit that referenced this issue Aug 23, 2022
Summary:
This diff introduces two main changes:

### Update Graph interface
Currently, `predecessors` and `successors` in Graph trait returns `&[Self::EdgeId]`, this would be fairly efficient for Graph implementations that can return a slice. But I realized that in many cases, the Graph implementations may only be able to return an iterator (e.g., using petgraph). To make the interface more flexible, I decide to update it.

There are three options for the new return type:
```
// 1. A iterator trait object (lazily evaluated, dynamic dispatch).
fn predecessors(&self, n: Self::NodeId) -> Box<dyn Iterator<Item = Self::EdgeId> + '_>;

// 2. Vector (heap alloc).
fn predecessors(&self, n: Self::NodeId) -> Vec<Self::EdgeId>;

// 3. SmallVec is similar to LLVM SmallVector, which can hold data in stack if its size is smaller than S.
fn predecessors(&self, n: Self::NodeId) -> SmallVec<[Self::EdgeId; S]>;
```

With some benchmarking using different numbers of successors (etc.,1, 2, 4, 6, 8, 10),  it turns out that the option #1 and #2 has similar performance, while option #3 is always slightly better than the other two. So I decided to adopt it. This will introduce a new dependency to our library but it's small. (later I can put this kind of benchmarking code in a separate bench folder.)

### Add a new trait for getting successor nodes

In WPO, we need an interface to query the successor nodes of a given node. Previously I used a closure for it (while the C++ version uses std::function). After discussing with yuxuanchen1997, we think it's better to make this a separate trait to achieve this, so we add `SuccessorNodes` (The type that implements Graph trait can also implement Fn trait, but it's not recommended in Rust). In most cases, the same type can implement both. But they can also be separate types.

In addition, this diff adds a naive graph implementation for testing. In this diff we only use it to test the `get_succ_nodes` interface.

Reviewed By: yuxuanchen1997

Differential Revision: D38846203

fbshipit-source-id: 7951b83a7df6817b3796c1a4e40d85e08b4c2c12
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

No branches or pull requests

2 participants