1414mutable struct Store{T} <: AbstractResource
1515 env :: Environment
1616 capacity :: UInt
17- items :: Set{T}
17+ load :: UInt
18+ items :: Dict{T, UInt}
1819 seid :: UInt
1920 put_queue :: DataStructures.PriorityQueue{Put, StorePutKey{T}}
2021 get_queue :: DataStructures.PriorityQueue{Get, StoreGetKey}
2122 function Store {T} (env:: Environment ; capacity:: UInt = typemax (UInt)) where {T}
22- new (env, capacity, Set {T } (), zero (UInt), DataStructures. PriorityQueue {Put, StorePutKey{T}} (), DataStructures. PriorityQueue {Get, StoreGetKey} ())
23+ new (env, capacity, zero (UInt), Dict {T, UInt } (), zero (UInt), DataStructures. PriorityQueue {Put, StorePutKey{T}} (), DataStructures. PriorityQueue {Get, StoreGetKey} ())
2324 end
2425end
2526
@@ -42,17 +43,23 @@ function get(sto::Store{T}, filter::Function=get_any_item; priority::Int=0) wher
4243end
4344
4445function do_put (sto:: Store{T} , put_ev:: Put , key:: StorePutKey{T} ) where {T}
45- if length (sto. items) < sto. capacity
46- push! (sto. items, key. item)
46+ if sto. load < sto. capacity
47+ sto. load += one (UInt)
48+ sto. items[key. item] = get! (sto. items, key. item, zero (UInt)) + one (UInt)
4749 schedule (put_ev)
4850 end
4951 false
5052end
5153
5254function do_get (sto:: Store{T} , get_ev:: Get , key:: StoreGetKey ) where {T}
53- for item in sto. items
55+ for ( item, number) in sto. items
5456 if key. filter (item)
55- delete! (sto. items, item)
57+ sto. load -= one (UInt)
58+ if number === one (UInt)
59+ delete! (sto. items, item)
60+ else
61+ sto. items[item] = number - one (UInt)
62+ end
5663 schedule (get_ev; value= item)
5764 break
5865 end
0 commit comments