| 8 | namespace function { |
| 9 | |
| 10 | static void normalizeIndices(int64_t& startIdx, int64_t& endIdx, uint64_t size) { |
| 11 | if (startIdx < 0) { |
| 12 | startIdx = size + startIdx + 1; |
| 13 | } |
| 14 | if (startIdx <= 0) { |
| 15 | startIdx = 1; |
| 16 | } |
| 17 | if (endIdx < 0) { |
| 18 | endIdx = size + endIdx + 1; |
| 19 | } |
| 20 | if (endIdx > (int64_t)size) { |
| 21 | endIdx = size; |
| 22 | } |
| 23 | if (endIdx < startIdx) { |
| 24 | startIdx = 1; |
| 25 | endIdx = 0; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | struct ListSlice { |
| 30 | // Note: this function takes in a 1-based begin/end index (The index of the first value in the |