Update the min value, comparing with the current value in MinState
| 101 | |
| 102 | // Update the min value, comparing with the current value in MinState |
| 103 | void MinUpdate(FunctionContext* context, const StringVal& input, BufferVal* val) { |
| 104 | if (input.is_null) return; |
| 105 | MinState* state = reinterpret_cast<MinState*>(*val); |
| 106 | if (state->value == NULL) { |
| 107 | state->Set(context, input); |
| 108 | return; |
| 109 | } |
| 110 | int cmp = memcmp(input.ptr, state->value, ::min(input.len, state->len)); |
| 111 | if (cmp < 0 || (cmp == 0 && input.len < state->len)) { |
| 112 | state->Set(context, input); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Serialize the state into the min string |
| 117 | BufferVal MinSerialize(FunctionContext* context, const BufferVal& intermediate) { |