No iterate method on Ordering

Viewed 45

I'm implementing the Ordering type according to the docs but I'm getting a missing method error. The docs don't say anything about needing to define iterate?

https://juliacollections.github.io/DataStructures.jl/v0.9/sorted_containers.html#Constructors-for-Sorted-Containers-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)
1 Answers

I think that you provide a type instead of a value :

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
Related