{
    "Function": "_sort",
    "File": "contracts/RubiconMarket.sol",
    "Parent Contracts": [
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "_find",
        "require(bool)",
        "_findpos",
        "isOfferSorted",
        "isActive"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function _sort(\n        uint256 id, //maker (ask) id\n        uint256 pos //position to insert into\n    ) internal {\n        require(isActive(id));\n\n        ERC20 buy_gem = offers[id].buy_gem;\n        ERC20 pay_gem = offers[id].pay_gem;\n        uint256 prev_id; //maker (ask) id\n\n        pos = pos == 0 ||\n            offers[pos].pay_gem != pay_gem ||\n            offers[pos].buy_gem != buy_gem ||\n            !isOfferSorted(pos)\n            ? _find(id)\n            : _findpos(id, pos);\n\n        if (pos != 0) {\n            //offers[id] is not the highest offer\n            //requirement below is satisfied by statements above\n            //require(_isPricedLtOrEq(id, pos));\n            prev_id = _rank[pos].prev;\n            _rank[pos].prev = id;\n            _rank[id].next = pos;\n        } else {\n            //offers[id] is the highest offer\n            prev_id = _best[address(pay_gem)][address(buy_gem)];\n            _best[address(pay_gem)][address(buy_gem)] = id;\n        }\n\n        if (prev_id != 0) {\n            //if lower offer does exist\n            //requirement below is satisfied by statements above\n            //require(!_isPricedLtOrEq(id, prev_id));\n            _rank[prev_id].next = id;\n            _rank[id].prev = prev_id;\n        }\n\n        _span[address(pay_gem)][address(buy_gem)]++;\n        emit LogSortedOffer(id);\n    }"
}