Ordering上没有迭代方法



我正在根据文档实现Ordering类型,但我得到了一个丢失的方法错误。文档没有说明需要定义迭代?

https://juliacollections.github.io/DataStructures.jl/v0.9/sorted_containers.html#Constructors-用于分拣集装箱-1

ERROR: LoadError: MethodError: no method matching iterate(::Type{BidOrdering})
using DataStructures
import Base.Ordering
import Base.lt
import DataStructures.eq
struct MBOBookEntity
orderid::Int64
price::String
orderPriority::Int64
displayQty::Int64
end
mutable struct MBOBook
bidBook::SortedSet{MBOBookEntity}
askBook::SortedSet{MBOBookEntity}
function MBOBook()
bidBook = SortedSet{MBOBookEntity}(BidOrdering)
askBook = SortedSet{MBOBookEntity}(AskOrdering)
new(bidBook, askBook)
end
end
struct BidOrdering <: Ordering end
struct AskOrdering <: Ordering end
lt(::BidOrdering, o1::MBOBookEntity, o2::MBOBookEntity) = begin
if o1.price == o2.price
return o1.orderPriority < o2.orderPriority
else
return o2.price < o1.price
end
end
eq(::BidOrdering, o1::MBOBookEntity, o2::MBOBookEntity) = isequal(o1.orderid, o2.orderid)

lt(::AskOrdering, o1::MBOBookEntity, o2::MBOBookEntity) = begin
if o1.price == o2.price
return o1.orderPriority < o2.orderPriority
else
return o1.price < o2.price
end
end
eq(::AskOrdering, o1::MBOBookEntity, o2::MBOBookEntity) = isequal(o1.orderid, o2.orderid)

我认为您提供的是类型,而不是

mutable struct MBOBook
bidBook::SortedSet{MBOBookEntity}
askBook::SortedSet{MBOBookEntity}
function MBOBook()
bidBook = SortedSet{MBOBookEntity}(BidOrdering()) # <- here, forgotten ()
askBook = SortedSet{MBOBookEntity}(AskOrdering()) # <- here, forgotten ()
new(bidBook, askBook)
end
end

最新更新