| 110 | } |
| 111 | |
| 112 | static OpResult SortInit(OpBase *opBase) { |
| 113 | OpSort *op = (OpSort *)opBase; |
| 114 | // if there is LIMIT value, l, set in the current clause, |
| 115 | // the operation must return the top l records with respect to |
| 116 | // the sorting criteria. In order to do so, it must collect the l records, |
| 117 | // but if there is a SKIP value, s, set, it must collect l+s records, |
| 118 | // sort them and return the top l |
| 119 | if(op->limit != UNLIMITED) { |
| 120 | op->limit += op->skip; |
| 121 | // if a limit is specified, use heapsort to poll the top N |
| 122 | op->heap = Heap_new((heap_cmp)_record_cmp, op); |
| 123 | } else { |
| 124 | // if all records are being sorted, use quicksort |
| 125 | op->buffer = array_new(Record, 32); |
| 126 | } |
| 127 | |
| 128 | uint comparison_count = array_len(op->exps); |
| 129 | op->record_offsets = array_new(uint, comparison_count); |
| 130 | for(uint i = 0; i < comparison_count; i ++) { |
| 131 | int record_idx; |
| 132 | bool aware = OpBase_Aware((OpBase *)op, op->exps[i]->resolved_name, |
| 133 | &record_idx); |
| 134 | ASSERT(aware); |
| 135 | array_append(op->record_offsets, record_idx); |
| 136 | } |
| 137 | |
| 138 | return OP_OK; |
| 139 | } |
| 140 | |
| 141 | static Record SortConsume(OpBase *opBase) { |
| 142 | OpSort *op = (OpSort *)opBase; |
nothing calls this directly
no test coverage detected