mercredi 22 avril 2020

Sort data in one way but retrieve in another way

I have a problem where I need to store floating points in sorted fashion. But while retrieving I want to use a different mechanism. Current storing in a std::set by overloading < operator

bool operator < (const SpanStruct_Y &b) const
{
    CommonTypes::Point p1 = mobIdentifier.startPoint, p2 = mobIdentifier.startPoint;
    CommonTypes::Point p3 = b.mobIdentifier.startPoint, p4 = b.mobIdentifier.startPoint;
    editPoint(p1, span, 270.0f + spanOrientation);
    editPoint(p2, span, 90.0f + spanOrientation);
    editPoint(p3, b.span, 270.0f + b.spanOrientation);
    editPoint(p4, b.span, 90.0f + b.spanOrientation);
    return cmpPoint_Y(cmpPointR_Y(p1,p2),cmpPointR_Y(p3,p4));
}

But while retrieving data I want to use say different values in the identifier. [mobileId and 2 index values]

struct uniqMobIdentifier
{
    CommonTypes::Point startPoint;
    uint16_t mobileId;
    uint16_t indexXInSpan;
    uint16_t indexYInSpan;

    uniqMobIdentifier()
    {
        startPoint = CommonTypes::Point();
        mobileId = DUMMY_ID;
        indexXInSpan = DUMMY_ID;
        indexYInSpan = DUMMY_ID;
    }

    uniqMobIdentifier(CommonTypes::Point p, uint16_t mobId, uint16_t x, uint16_t y)
    {
        startPoint = p;
        mobileId = mobId;
        indexXInSpan = x;
        indexYInSpan = y;
    }

    uniqMobIdentifier& operator =(const uniqMobIdentifier& a)
    {
        startPoint = a.startPoint;
        mobileId = a.mobileId;
        indexXInSpan = a.indexXInSpan;
        indexYInSpan = a.indexYInSpan;
        return *this;
    }

    bool operator==(const uniqMobIdentifier& a) const
    {
        return (((std::abs(startPoint.m_xCoordinate - a.startPoint.m_xCoordinate) < POINT_DISTANCE_TOLERANCE)
                || (std::abs(startPoint.m_yCoordinate - a.startPoint.m_yCoordinate) < POINT_DISTANCE_TOLERANCE))
                && mobileId == a.mobileId && indexXInSpan == a.indexXInSpan && indexYInSpan == indexYInSpan);
    }


    bool operator!=(const uniqMobIdentifier& a) const
    {
        return (/*((std::abs(startPoint.m_xCoordinate - a.startPoint.m_xCoordinate) > POINT_DISTANCE_TOLERANCE)
                || (std::abs(startPoint.m_yCoordinate - a.startPoint.m_yCoordinate) > POINT_DISTANCE_TOLERANCE))
                && */
                !(mobileId == a.mobileId) && !(indexXInSpan == a.indexXInSpan) && !(indexYInSpan == indexYInSpan));
    }


};

Is it possible to do so? Is there a better way of doing it?

Aucun commentaire:

Enregistrer un commentaire