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

Make Store.items a dequeue #56

Closed
riccardosven opened this issue Jun 20, 2018 · 9 comments
Closed

Make Store.items a dequeue #56

riccardosven opened this issue Jun 20, 2018 · 9 comments

Comments

@riccardosven
Copy link
Contributor

Is there a specific reason why Store.items is a Set{T}?
In my opinion it makes for some counterintuitive behavior. For instance,

env = Simulation()
store = Store{Symbol}(env)
put(store, :apple)
put(store, :apple)
put(store, :pear)

gives

store.items
Set(Symbol[:pear, :apple])

which is counterintuitive as one would expect the store to contain two apples now; however, before making a pr, I wanted to know if there is some specific idea behind using Set.

@BenLauwens
Copy link
Collaborator

Sorry for the late answer ... SimJulia had a low priority but it will be better in the future;)
A Dequeue is more logical. I will implement it.

@BenLauwens
Copy link
Collaborator

The problem with Deque is that it does not allow to delete an arbitrary element.
I have used a Store only with mutable objects. For immutable type we have that a==b is identical to a===b.
One way I can solve this, is boxing immutable types...

@hdavid16
Copy link
Member

What is the path forward here?

@BenLauwens
Copy link
Collaborator

Boxing immutable objects or using a Dict with as key the object and as value the number of times it is stored. Both are doable. I have a slight preference for the latter. All input is welcome!

@hdavid16
Copy link
Member

I definitely vote for the latter as well. I'm not a fan of boxing and using a dictionary would make it clear how many items you have.

@BenLauwens
Copy link
Collaborator

BenLauwens commented May 25, 2021

I had some spare time;) straightforward implementation of a Store based on a Dict is in the master branch.

julia> using SimJulia

julia> env = Simulation()
Simulation time: 0.0 active_process: nothing

julia> store = Store{Symbol}(env)
Store{Symbol}

julia> put(store, :apple)
SimJulia.Put 1

julia> put(store, :apple)
SimJulia.Put 2

julia> put(store, :pear)
SimJulia.Put 3

julia> store.items
Dict{Symbol, UInt64} with 2 entries:
  :pear  => 0x0000000000000001
  :apple => 0x0000000000000002

What do you think?

@hdavid16
Copy link
Member

Looks great. I've started using this already. Unless you think it needs further work, I think we can close this issue.

@hdavid16
Copy link
Member

I've been using this new implementation and it works great for my purposes. Unless @riccardosven suggests otherwise, we should close this issue.

@riccardosven
Copy link
Contributor Author

I agree! Closed

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

3 participants