Created
November 11, 2020 20:48
-
-
Save 0xAnonymous/7f32aae2866741259447c2ff1fe51da8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Oracle { | |
mapping (uint => uint) public seed; | |
mapping (uint => mapping (uint => uint)) public points; | |
mapping (uint => uint[]) public leaderboard; | |
mapping (uint => mapping (uint => uint)) public leaderboardIndex; | |
struct Score { | |
uint start; | |
uint end; | |
} | |
mapping (uint => mapping (uint => Score)) public segments; | |
function _vote(uint _id, uint _t) internal { | |
uint score = points[_t][_id]; | |
if(score == 0) { | |
leaderboard[_t].push(_id); | |
leaderboardIndex[_t][_id] = leaderboard[_t].length; | |
if(segments[_t][1].end == 0) segments[_t][1].end = leaderboard[_t].length; | |
segments[_t][1].start = leaderboard[_t].length; | |
} | |
else { | |
uint index = leaderboardIndex[_t][_id]; | |
uint nextSegment = segments[_t][score].end; | |
if(nextSegment != index) { | |
leaderboardIndex[_t][_id] = nextSegment; | |
leaderboardIndex[_t][leaderboard[_t][nextSegment-1]] = index; | |
(leaderboard[_t][nextSegment - 1], leaderboard[_t][index - 1]) = (leaderboard[_t][index - 1], leaderboard[_t][nextSegment - 1]); | |
} | |
if(segments[_t][score].start == nextSegment) { | |
delete segments[_t][score].start; | |
delete segments[_t][score].end; | |
} | |
else segments[_t][score].end++; | |
if(segments[_t][score+1].end == 0) segments[_t][score+1].end = nextSegment; | |
segments[_t][score+1].start = nextSegment; | |
} | |
points[_t][_id]++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment