mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-25 08:53:55 +00:00
bifs/arithmetic_test.go
This commit is contained in:
parent
012e707917
commit
511a1bf3ee
32 changed files with 325 additions and 108 deletions
3
.vimrc
3
.vimrc
|
|
@ -3,4 +3,5 @@ map \r :w<C-m>:!clear;echo Building ...; echo; make tests-in-order<C-m>
|
|||
"map \f :w<C-m>:!clear;echo Building ...; echo; make mlrval-tests<C-m>
|
||||
"map \f :w<C-m>:!clear;echo Building ...; echo; make mlrmap-tests<C-m>
|
||||
"map \f :w<C-m>:!clear;echo Building ...; echo; make input-tests<C-m>
|
||||
map \f :w<C-m>:!clear;echo Building ...; echo; make mlrval-format-test<C-m>
|
||||
"map \f :w<C-m>:!clear;echo Building ...; echo; make mlrval-format-test<C-m>
|
||||
map \f :w<C-m>:!clear;echo Building ...; echo; make bifs-tests<C-m>
|
||||
|
|
|
|||
29
Makefile
29
Makefile
|
|
@ -96,12 +96,39 @@ input-dkvp-test:
|
|||
internal/pkg/input/record_reader_dkvp_nidx.go
|
||||
input-tests: input-dkvp-test
|
||||
|
||||
bifs-arithmetic-test:
|
||||
go test internal/pkg/bifs/arithmetic_test.go \
|
||||
internal/pkg/bifs/base.go \
|
||||
internal/pkg/bifs/arithmetic.go
|
||||
bifs-bits-test:
|
||||
go test internal/pkg/bifs/bits_test.go \
|
||||
internal/pkg/bifs/base.go \
|
||||
internal/pkg/bifs/arithmetic.go \
|
||||
internal/pkg/bifs/bits.go
|
||||
bifs-collections-test:
|
||||
go test internal/pkg/bifs/bits_test.go \
|
||||
internal/pkg/bifs/base.go \
|
||||
internal/pkg/bifs/arithmetic.go \
|
||||
internal/pkg/bifs/collections.go
|
||||
bifs-hashing-test:
|
||||
go test internal/pkg/bifs/hashing_test.go \
|
||||
internal/pkg/bifs/base.go \
|
||||
internal/pkg/bifs/arithmetic.go \
|
||||
internal/pkg/bifs/hashing.go
|
||||
bifs-sort-test:
|
||||
go test internal/pkg/bifs/sort_test.go \
|
||||
internal/pkg/bifs/base.go \
|
||||
internal/pkg/bifs/arithmetic.go \
|
||||
internal/pkg/bifs/sort.go
|
||||
|
||||
bifs-tests: bifs-arithmetic-test bifs-bits-test bifs-collections-test bifs-hashing-test bifs-sort-test
|
||||
|
||||
#mlrval_functions_test:
|
||||
# go test internal/pkg/types/mlrval_functions_test.go $(ls internal/pkg/types/*.go | grep -v test)
|
||||
#mlrval_format_test:
|
||||
# go test internal/pkg/types/mlrval_format_test.go $(ls internal/pkg/types/*.go|grep -v test)
|
||||
|
||||
tests-in-order: mlrval-tests mlrmap-tests input-tests
|
||||
tests-in-order: mlrval-tests mlrmap-tests input-tests bifs-tests
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Regression tests (large number)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
|
@ -56,20 +56,9 @@ func BIF_minus_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
return uneg_dispositions[input1.Type()](input1)
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Logical NOT operator
|
||||
|
||||
func BIF_logicalnot(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsBool() {
|
||||
return mlrval.FromBool(!input1.AcquireBoolValue())
|
||||
} else {
|
||||
return mlrval.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Addition with auto-overflow from int to float when necessary. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
// Auto-overflows up to float. Additions & subtractions overflow by at most
|
||||
// one bit so it suffices to check sign-changes.
|
||||
|
|
@ -127,7 +116,7 @@ func BIF_plus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Subtraction with auto-overflow from int to float when necessary. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
// Adds & subtracts overflow by at most one bit so it suffices to check
|
||||
// sign-changes.
|
||||
|
|
@ -185,7 +174,7 @@ func BIF_minus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Multiplication with auto-overflow from int to float when necessary. See
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
// Auto-overflows up to float.
|
||||
//
|
||||
|
|
@ -259,7 +248,7 @@ func BIF_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Pythonic division. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
//
|
||||
// Int/int pairings don't produce overflow.
|
||||
//
|
||||
|
|
@ -330,7 +319,7 @@ func BIF_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Integer division: DSL operator '//' as in Python. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func int_divide_n_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
a := input1.AcquireIntValue()
|
||||
|
|
@ -391,7 +380,7 @@ func BIF_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Non-auto-overflowing addition: DSL operator '.+'. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func dotplus_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromInt(input1.AcquireIntValue() + input2.AcquireIntValue())
|
||||
|
|
@ -427,7 +416,7 @@ func BIF_dot_plus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ================================================================
|
||||
// Non-auto-overflowing subtraction: DSL operator '.-'. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func dotminus_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromInt(input1.AcquireIntValue() - input2.AcquireIntValue())
|
||||
|
|
@ -463,7 +452,7 @@ func BIF_dot_minus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ----------------------------------------------------------------
|
||||
// Non-auto-overflowing multiplication: DSL operator '.*'. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func dottimes_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromInt(input1.AcquireIntValue() * input2.AcquireIntValue())
|
||||
|
|
@ -499,7 +488,7 @@ func BIF_dot_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ----------------------------------------------------------------
|
||||
// 64-bit integer division: DSL operator './'. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func dotdivide_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromInt(input1.AcquireIntValue() / input2.AcquireIntValue())
|
||||
|
|
@ -535,7 +524,7 @@ func BIF_dot_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ----------------------------------------------------------------
|
||||
// 64-bit integer division: DSL operator './/'. See also
|
||||
// https://johnkerl.org/miller6/reference-main-arithmetic.html
|
||||
// https://miller.readthedocs.io/en/latest/reference-main-arithmetic
|
||||
|
||||
func dotidivide_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
a := input1.AcquireIntValue()
|
||||
|
|
@ -590,7 +579,7 @@ var dotidivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
|
|||
/*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro},
|
||||
}
|
||||
|
||||
func MlrvalDotIntDivide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_dot_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return dotidivide_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
}
|
||||
|
||||
|
|
@ -826,7 +815,7 @@ var min_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
|
|||
/*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro},
|
||||
}
|
||||
|
||||
func MlrvalBinaryMin(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_min_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return (min_dispositions[input1.Type()][input2.Type()])(input1, input2)
|
||||
}
|
||||
|
||||
|
|
@ -837,7 +826,7 @@ func BIF_min_variadic(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval {
|
|||
retval := mlrvals[0]
|
||||
for i := range mlrvals {
|
||||
if i > 0 {
|
||||
retval = MlrvalBinaryMin(retval, mlrvals[i])
|
||||
retval = BIF_min_binary(retval, mlrvals[i])
|
||||
}
|
||||
}
|
||||
return retval
|
||||
|
|
@ -910,7 +899,7 @@ var max_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{
|
|||
/*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro},
|
||||
}
|
||||
|
||||
func MlrvalBinaryMax(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_max_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return (max_dispositions[input1.Type()][input2.Type()])(input1, input2)
|
||||
}
|
||||
|
||||
|
|
@ -921,7 +910,7 @@ func BIF_max_variadic(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval {
|
|||
retval := mlrvals[0]
|
||||
for i := range mlrvals {
|
||||
if i > 0 {
|
||||
retval = MlrvalBinaryMax(retval, mlrvals[i])
|
||||
retval = BIF_max_binary(retval, mlrvals[i])
|
||||
}
|
||||
}
|
||||
return retval
|
||||
|
|
|
|||
90
internal/pkg/bifs/arithmetic_test.go
Normal file
90
internal/pkg/bifs/arithmetic_test.go
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
package bifs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
)
|
||||
|
||||
func TestBIF_plus_unary(t *testing.T) {
|
||||
input := mlrval.FromDeferredType("123")
|
||||
output := BIF_plus_unary(input)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 123, intval)
|
||||
|
||||
input = mlrval.FromDeferredType("-123.5")
|
||||
output = BIF_plus_unary(input)
|
||||
floatval, ok := output.GetFloatValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, -123.5, floatval)
|
||||
}
|
||||
|
||||
func TestBIF_minus_unary(t *testing.T) {
|
||||
input := mlrval.FromDeferredType("123")
|
||||
output := BIF_minus_unary(input)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, -123, intval)
|
||||
|
||||
input = mlrval.FromDeferredType("-123.5")
|
||||
output = BIF_minus_unary(input)
|
||||
floatval, ok := output.GetFloatValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 123.5, floatval)
|
||||
}
|
||||
|
||||
func TestBIF_plus_binary(t *testing.T) {
|
||||
input1 := mlrval.FromDeferredType("123")
|
||||
input2 := mlrval.FromDeferredType("456")
|
||||
output := BIF_plus_binary(input1, input2)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 579, intval)
|
||||
|
||||
input1 = mlrval.FromDeferredType("123.5")
|
||||
input2 = mlrval.FromDeferredType("456")
|
||||
output = BIF_plus_binary(input1, input2)
|
||||
floatval, ok := output.GetFloatValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 579.5, floatval)
|
||||
}
|
||||
|
||||
func TestBIF_plus_binary_overflow(t *testing.T) {
|
||||
input1 := mlrval.FromInt(0x07ffffffffffffff)
|
||||
input2 := mlrval.FromInt(0x07fffffffffffffe)
|
||||
output := BIF_plus_binary(input1, input2)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 0x0ffffffffffffffd, intval)
|
||||
|
||||
input1 = mlrval.FromInt(0x7fffffffffffffff)
|
||||
input2 = mlrval.FromInt(0x7ffffffffffffffe)
|
||||
output = BIF_plus_binary(input1, input2)
|
||||
floatval, ok := output.GetFloatValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 18446744073709552000.0, floatval)
|
||||
}
|
||||
|
||||
// TODO: copy in more unit-test cases from existing regression-test data
|
||||
|
||||
//func BIF_minus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_dot_plus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_dot_minus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_dot_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_dot_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_dot_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_modulus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_mod_add(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_mod_sub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_mod_mul(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_mod_exp(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_min_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_min_variadic(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_max_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
//func BIF_max_variadic(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
// ('s') to anything else ('x').
|
||||
// ================================================================
|
||||
|
||||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
|
|
|
|||
19
internal/pkg/bifs/bits_test.go
Normal file
19
internal/pkg/bifs/bits_test.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package bifs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
)
|
||||
|
||||
func TestBIF_bitcount(t *testing.T) {
|
||||
input1 := mlrval.FromDeferredType("0xcafe")
|
||||
output := BIF_bitcount(input1)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 11, intval)
|
||||
}
|
||||
|
||||
// TODO: copy in more unit-test cases from existing regression-test data
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Boolean expressions for ==, !=, >, >=, <, <=
|
||||
// ================================================================
|
||||
|
||||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"github.com/johnkerl/miller/internal/pkg/lib"
|
||||
|
|
@ -400,7 +400,7 @@ func BIF_cmp(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
|
||||
// For Go's sort.Slice.
|
||||
func MlrvalLessThanAsBool(input1, input2 *mlrval.Mlrval) bool {
|
||||
func BIF_less_than_as_bool(input1, input2 *mlrval.Mlrval) bool {
|
||||
// TODO refactor to avoid copy
|
||||
// This is a hot path for sort GC and is worth significant hand-optimization
|
||||
mretval := lt_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
|
|
@ -410,7 +410,7 @@ func MlrvalLessThanAsBool(input1, input2 *mlrval.Mlrval) bool {
|
|||
}
|
||||
|
||||
// For Go's sort.Slice.
|
||||
func MlrvalLessThanOrEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
||||
func BIF_less_than_or_equals_as_bool(input1, input2 *mlrval.Mlrval) bool {
|
||||
// TODO refactor to avoid copy
|
||||
// This is a hot path for sort GC and is worth significant hand-optimization
|
||||
mretval := le_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
|
|
@ -420,7 +420,7 @@ func MlrvalLessThanOrEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
|||
}
|
||||
|
||||
// For top-keeper
|
||||
func MlrvalGreaterThanAsBool(input1, input2 *mlrval.Mlrval) bool {
|
||||
func BIF_greater_than_as_bool(input1, input2 *mlrval.Mlrval) bool {
|
||||
// TODO refactor to avoid copy
|
||||
// This is a hot path for sort GC and is worth significant hand-optimization
|
||||
mretval := gt_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
|
|
@ -430,7 +430,7 @@ func MlrvalGreaterThanAsBool(input1, input2 *mlrval.Mlrval) bool {
|
|||
}
|
||||
|
||||
// For top-keeper
|
||||
func MlrvalGreaterThanOrEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
||||
func BIF_greater_than_or_equals_as_bool(input1, input2 *mlrval.Mlrval) bool {
|
||||
// TODO refactor to avoid copy
|
||||
// This is a hot path for sort GC and is worth significant hand-optimization
|
||||
mretval := ge_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
|
|
@ -440,7 +440,7 @@ func MlrvalGreaterThanOrEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
|||
}
|
||||
|
||||
// Convenience wrapper for non-DSL callsites that just want a bool
|
||||
func MlrvalEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
||||
func BIF_equals_as_bool(input1, input2 *mlrval.Mlrval) bool {
|
||||
mretval := eq_dispositions[input1.Type()][input2.Type()](input1, input2)
|
||||
retval, ok := mretval.GetBoolValue()
|
||||
lib.InternalCodingErrorIf(!ok)
|
||||
|
|
@ -448,7 +448,15 @@ func MlrvalEqualsAsBool(input1, input2 *mlrval.Mlrval) bool {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalLogicalAND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_logical_NOT(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsBool() {
|
||||
return mlrval.FromBool(!input1.AcquireBoolValue())
|
||||
} else {
|
||||
return mlrval.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
func BIF_logical_AND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsBool() && input2.IsBool() {
|
||||
return mlrval.FromBool(input1.AcquireBoolValue() && input2.AcquireBoolValue())
|
||||
} else {
|
||||
|
|
@ -456,7 +464,7 @@ func MlrvalLogicalAND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
}
|
||||
|
||||
func MlrvalLogicalOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_logical_OR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsBool() && input2.IsBool() {
|
||||
return mlrval.FromBool(input1.AcquireBoolValue() || input2.AcquireBoolValue())
|
||||
} else {
|
||||
|
|
@ -464,7 +472,7 @@ func MlrvalLogicalOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
}
|
||||
|
||||
func BIF_logicalxor(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_logical_XOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
if input1.IsBool() && input2.IsBool() {
|
||||
return mlrval.FromBool(input1.AcquireBoolValue() != input2.AcquireBoolValue())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -573,12 +573,12 @@ func BIF_splitax(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
input := input1.AcquireStringValue()
|
||||
fieldSeparator := input2.AcquireStringValue()
|
||||
|
||||
return mlrvalSplitAXHelper(input, fieldSeparator)
|
||||
return bif_splitax_helper(input, fieldSeparator)
|
||||
}
|
||||
|
||||
// mlrvalSplitAXHelper is Split out for the benefit of BIF_splitax and
|
||||
// bif_splitax_helper is split out for the benefit of BIF_splitax and
|
||||
// BIF_unflatten.
|
||||
func mlrvalSplitAXHelper(input string, separator string) *mlrval.Mlrval {
|
||||
func bif_splitax_helper(input string, separator string) *mlrval.Mlrval {
|
||||
fields := lib.SplitString(input, separator)
|
||||
|
||||
output := NewSizedMlrvalArray(int(len(fields)))
|
||||
|
|
|
|||
56
internal/pkg/bifs/collections_test.go
Normal file
56
internal/pkg/bifs/collections_test.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package bifs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
)
|
||||
|
||||
func TestBIF_length(t *testing.T) {
|
||||
input1 := mlrval.FromInt(123)
|
||||
output := BIF_length(input1)
|
||||
intval, ok := output.GetIntValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 1, intval)
|
||||
}
|
||||
|
||||
// TODO: copy in more unit-test cases from existing regression-test data
|
||||
|
||||
// func BIF_length(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func depth_from_array(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func depth_from_map(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func depth_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_depth(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func leafcount_from_array(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func leafcount_from_map(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func leafcount_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_leafcount(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func has_key_in_array(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func has_key_in_map(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_haskey(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_mapselect(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_mapexcept(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_mapsum(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_mapdiff(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_joink(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_joinv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_joinkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splitkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splitkvx(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splitnv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splitnvx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splita(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_splitax(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func mlrvalSplitAXHelper(input string, separator string) *mlrval.Mlrval
|
||||
// func BIF_get_keys(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_get_values(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_append(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_flatten(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_flatten_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_unflatten(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_arrayify(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_json_parse(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_json_stringify_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
// func BIF_json_stringify_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
|
|
|
|||
25
internal/pkg/bifs/hashing_test.go
Normal file
25
internal/pkg/bifs/hashing_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package bifs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
)
|
||||
|
||||
func TestBIF_md5(t *testing.T) {
|
||||
input1 := mlrval.FromDeferredType("")
|
||||
output := BIF_md5(input1)
|
||||
stringval, ok := output.GetStringValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", stringval)
|
||||
|
||||
input1 = mlrval.FromDeferredType("miller")
|
||||
output = BIF_md5(input1)
|
||||
stringval, ok = output.GetStringValue()
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "f0af962ddbc82430e947390b2f3f6e49", stringval)
|
||||
}
|
||||
|
||||
// TODO: copy in more unit-test cases from existing regression-test data
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Go math-library functions
|
||||
// ================================================================
|
||||
|
||||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// For sorting
|
||||
// ================================================================
|
||||
|
||||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
// ================================================================
|
||||
// Most Miller tests (thousands of them) are command-line-driven via
|
||||
// mlr regtest. Here are some cases needing special focus.
|
||||
// ================================================================
|
||||
|
||||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/mlrval"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
|
@ -24,7 +24,7 @@ import (
|
|||
// output = [m, b, math.sqrt(var_m), math.sqrt(var_b)]
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalGetVar(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_get_var(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
n, isInt := mn.GetIntValue()
|
||||
lib.InternalCodingErrorIf(!isInt)
|
||||
sum, isNumber := msum.GetNumericToFloatValue()
|
||||
|
|
@ -46,8 +46,8 @@ func MlrvalGetVar(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalGetStddev(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
mvar := MlrvalGetVar(mn, msum, msum2)
|
||||
func BIF_get_stddev(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
mvar := BIF_get_var(mn, msum, msum2)
|
||||
if mvar.IsVoid() {
|
||||
return mvar
|
||||
}
|
||||
|
|
@ -55,8 +55,8 @@ func MlrvalGetStddev(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalGetMeanEB(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
mvar := MlrvalGetVar(mn, msum, msum2)
|
||||
func BIF_get_mean_EB(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
mvar := BIF_get_var(mn, msum, msum2)
|
||||
if mvar.IsVoid() {
|
||||
return mvar
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ func MlrvalGetMeanEB(mn, msum, msum2 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
// = sumx2 - n mean^2
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalGetSkewness(mn, msum, msum2, msum3 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_get_skewness(mn, msum, msum2, msum3 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
n, isInt := mn.GetIntValue()
|
||||
lib.InternalCodingErrorIf(!isInt)
|
||||
if n < 2 {
|
||||
|
|
@ -124,7 +124,7 @@ func MlrvalGetSkewness(mn, msum, msum2, msum3 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
// = sumx4 - mean*(4 sumx3 - mean*(6 sumx2 - 3 n mean^2))
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func MlrvalGetKurtosis(mn, msum, msum2, msum3, msum4 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
func BIF_get_kurtosis(mn, msum, msum2, msum3, msum4 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
n, isInt := mn.GetIntValue()
|
||||
lib.InternalCodingErrorIf(!isInt)
|
||||
if n < 2 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
|
@ -217,10 +217,10 @@ func BIF_strip(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
|
||||
// ----------------------------------------------------------------
|
||||
func BIF_collapse_whitespace(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return MlrvalCollapseWhitespaceRegexp(input1, WhitespaceRegexp())
|
||||
return BIF_collapse_whitespace_regexp(input1, WhitespaceRegexp())
|
||||
}
|
||||
|
||||
func MlrvalCollapseWhitespaceRegexp(input1 *mlrval.Mlrval, whitespaceRegexp *regexp.Regexp) *mlrval.Mlrval {
|
||||
func BIF_collapse_whitespace_regexp(input1 *mlrval.Mlrval, whitespaceRegexp *regexp.Regexp) *mlrval.Mlrval {
|
||||
if input1.IsString() {
|
||||
return mlrval.FromString(whitespaceRegexp.ReplaceAllString(input1.AcquireStringValue(), " "))
|
||||
} else {
|
||||
|
|
@ -273,7 +273,7 @@ func BIF_capitalize(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
// ----------------------------------------------------------------
|
||||
func BIF_clean_whitespace(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return BIF_strip(
|
||||
MlrvalCollapseWhitespaceRegexp(
|
||||
BIF_collapse_whitespace_regexp(
|
||||
input1, WhitespaceRegexp(),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package bifs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ func makeBuiltinFunctionLookupTable() []BuiltinFunctionInfo {
|
|||
name: "!",
|
||||
class: FUNC_CLASS_BOOLEAN,
|
||||
help: `Logical negation.`,
|
||||
unaryFunc: types.BIF_logicalnot,
|
||||
unaryFunc: types.BIF_logical_NOT,
|
||||
},
|
||||
|
||||
{
|
||||
|
|
@ -348,7 +348,7 @@ func makeBuiltinFunctionLookupTable() []BuiltinFunctionInfo {
|
|||
name: "^^",
|
||||
class: FUNC_CLASS_BOOLEAN,
|
||||
help: `Logical XOR.`,
|
||||
binaryFunc: types.BIF_logicalxor,
|
||||
binaryFunc: types.BIF_logical_XOR,
|
||||
},
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -805,7 +805,7 @@ func (node *LogicalANDOperatorNode) Evaluate(
|
|||
return types.MLRVAL_ABSENT
|
||||
}
|
||||
|
||||
return mlrval.MlrvalLogicalAND(aout, bout)
|
||||
return mlrval.BIF_logical_AND(aout, bout)
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
|
|
@ -852,7 +852,7 @@ func (node *LogicalOROperatorNode) Evaluate(
|
|||
if btype == types.MT_ABSENT {
|
||||
return types.MLRVAL_ABSENT
|
||||
}
|
||||
return mlrval.MlrvalLogicalOR(aout, bout)
|
||||
return mlrval.BIF_logical_OR(aout, bout)
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
|
|
|
|||
|
|
@ -616,11 +616,11 @@ func sortA(
|
|||
func sortANumerical(array []mlrval.Mlrval, reverse bool) {
|
||||
if !reverse {
|
||||
sort.Slice(array, func(i, j int) bool {
|
||||
return mlrval.MlrvalLessThanAsBool(&array[i], &array[j])
|
||||
return mlrval.BIF_less_than_as_bool(&array[i], &array[j])
|
||||
})
|
||||
} else {
|
||||
sort.Slice(array, func(i, j int) bool {
|
||||
return mlrval.MlrvalGreaterThanAsBool(&array[i], &array[j])
|
||||
return mlrval.BIF_greater_than_as_bool(&array[i], &array[j])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ func (tr *TransformerFraction) Transform(
|
|||
}
|
||||
|
||||
denominator := sumsForGroup[fractionFieldName]
|
||||
if !mlrval.MlrvalEqualsAsBool(value, tr.zero) {
|
||||
if !mlrval.BIF_equals_as_bool(value, tr.zero) {
|
||||
outputValue = bifs.BIF_divide(numerator, denominator)
|
||||
outputValue = bifs.BIF_times(outputValue, tr.multiplier)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ func getPercentileLinearlyInterpolated(array []*mlrval.Mlrval, n int, p float64)
|
|||
func (keeper *PercentileKeeper) sortIfNecessary() {
|
||||
if !keeper.sorted {
|
||||
sort.Slice(keeper.data, func(i, j int) bool {
|
||||
return mlrval.MlrvalLessThanAsBool(keeper.data[i], keeper.data[j])
|
||||
return mlrval.BIF_less_than_as_bool(keeper.data[i], keeper.data[j])
|
||||
})
|
||||
keeper.sorted = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -440,7 +440,7 @@ func NewStats1MinAccumulator() IStats1Accumulator {
|
|||
}
|
||||
}
|
||||
func (acc *Stats1MinAccumulator) Ingest(value *mlrval.Mlrval) {
|
||||
acc.min = mlrval.MlrvalBinaryMin(acc.min, value)
|
||||
acc.min = mlrval.BIF_min_binary(acc.min, value)
|
||||
}
|
||||
func (acc *Stats1MinAccumulator) Emit() *mlrval.Mlrval {
|
||||
if acc.min.IsAbsent() {
|
||||
|
|
@ -464,7 +464,7 @@ func NewStats1MaxAccumulator() IStats1Accumulator {
|
|||
}
|
||||
}
|
||||
func (acc *Stats1MaxAccumulator) Ingest(value *mlrval.Mlrval) {
|
||||
acc.max = mlrval.MlrvalBinaryMax(acc.max, value)
|
||||
acc.max = mlrval.BIF_max_binary(acc.max, value)
|
||||
}
|
||||
func (acc *Stats1MaxAccumulator) Emit() *mlrval.Mlrval {
|
||||
if acc.max.IsAbsent() {
|
||||
|
|
@ -498,7 +498,7 @@ func (acc *Stats1VarAccumulator) Ingest(value *mlrval.Mlrval) {
|
|||
acc.sum2 = types.BIF_plus_binary(acc.sum2, value2)
|
||||
}
|
||||
func (acc *Stats1VarAccumulator) Emit() *mlrval.Mlrval {
|
||||
return mlrval.MlrvalGetVar(mlrval.MlrvalFromInt(acc.count), acc.sum, acc.sum2)
|
||||
return mlrval.BIF_get_var(mlrval.MlrvalFromInt(acc.count), acc.sum, acc.sum2)
|
||||
}
|
||||
func (acc *Stats1VarAccumulator) Reset() {
|
||||
acc.count = 0
|
||||
|
|
@ -527,7 +527,7 @@ func (acc *Stats1StddevAccumulator) Ingest(value *mlrval.Mlrval) {
|
|||
acc.sum2 = types.BIF_plus_binary(acc.sum2, value2)
|
||||
}
|
||||
func (acc *Stats1StddevAccumulator) Emit() *mlrval.Mlrval {
|
||||
return mlrval.MlrvalGetStddev(mlrval.MlrvalFromInt(acc.count), acc.sum, acc.sum2)
|
||||
return mlrval.BIF_get_stddev(mlrval.MlrvalFromInt(acc.count), acc.sum, acc.sum2)
|
||||
}
|
||||
func (acc *Stats1StddevAccumulator) Reset() {
|
||||
acc.count = 0
|
||||
|
|
@ -557,7 +557,7 @@ func (acc *Stats1MeanEBAccumulator) Ingest(value *mlrval.Mlrval) {
|
|||
}
|
||||
func (acc *Stats1MeanEBAccumulator) Emit() *mlrval.Mlrval {
|
||||
mcount := mlrval.MlrvalFromInt(acc.count)
|
||||
return mlrval.MlrvalGetMeanEB(mcount, acc.sum, acc.sum2)
|
||||
return mlrval.BIF_get_mean_EB(mcount, acc.sum, acc.sum2)
|
||||
}
|
||||
func (acc *Stats1MeanEBAccumulator) Reset() {
|
||||
acc.count = 0
|
||||
|
|
@ -591,7 +591,7 @@ func (acc *Stats1SkewnessAccumulator) Ingest(value *mlrval.Mlrval) {
|
|||
}
|
||||
func (acc *Stats1SkewnessAccumulator) Emit() *mlrval.Mlrval {
|
||||
mcount := mlrval.MlrvalFromInt(acc.count)
|
||||
return mlrval.MlrvalGetSkewness(mcount, acc.sum, acc.sum2, acc.sum3)
|
||||
return mlrval.BIF_get_skewness(mcount, acc.sum, acc.sum2, acc.sum3)
|
||||
}
|
||||
func (acc *Stats1SkewnessAccumulator) Reset() {
|
||||
acc.count = 0
|
||||
|
|
@ -630,7 +630,7 @@ func (acc *Stats1KurtosisAccumulator) Ingest(value *mlrval.Mlrval) {
|
|||
}
|
||||
func (acc *Stats1KurtosisAccumulator) Emit() *mlrval.Mlrval {
|
||||
mcount := mlrval.MlrvalFromInt(acc.count)
|
||||
return mlrval.MlrvalGetKurtosis(mcount, acc.sum, acc.sum2, acc.sum3, acc.sum4)
|
||||
return mlrval.BIF_get_kurtosis(mcount, acc.sum, acc.sum2, acc.sum3, acc.sum4)
|
||||
}
|
||||
func (acc *Stats1KurtosisAccumulator) Reset() {
|
||||
acc.count = 0
|
||||
|
|
|
|||
|
|
@ -575,18 +575,18 @@ func BsearchMlrvalArrayForDescendingInsert(
|
|||
return 0
|
||||
}
|
||||
|
||||
if MlrvalGreaterThanAsBool(value, (*array)[0]) {
|
||||
if BIF_greater_than_as_bool(value, (*array)[0]) {
|
||||
return 0
|
||||
}
|
||||
if MlrvalLessThanAsBool(value, (*array)[hi]) {
|
||||
if BIF_less_than_as_bool(value, (*array)[hi]) {
|
||||
return size
|
||||
}
|
||||
|
||||
for lo < hi {
|
||||
middleElement := (*array)[mid]
|
||||
if MlrvalEqualsAsBool(value, middleElement) {
|
||||
if BIF_equals_as_bool(value, middleElement) {
|
||||
return mid
|
||||
} else if MlrvalGreaterThanAsBool(value, middleElement) {
|
||||
} else if BIF_greater_than_as_bool(value, middleElement) {
|
||||
hi = mid
|
||||
newmid = (hi + lo) / 2
|
||||
} else {
|
||||
|
|
@ -594,9 +594,9 @@ func BsearchMlrvalArrayForDescendingInsert(
|
|||
newmid = (hi + lo) / 2
|
||||
}
|
||||
if mid == newmid {
|
||||
if MlrvalGreaterThanOrEqualsAsBool(value, (*array)[lo]) {
|
||||
if BIF_greater_than_or_equals_as_bool(value, (*array)[lo]) {
|
||||
return lo
|
||||
} else if MlrvalGreaterThanOrEqualsAsBool(value, (*array)[hi]) {
|
||||
} else if BIF_greater_than_or_equals_as_bool(value, (*array)[hi]) {
|
||||
return hi
|
||||
} else {
|
||||
return hi + 1
|
||||
|
|
@ -622,18 +622,18 @@ func BsearchMlrvalArrayForAscendingInsert(
|
|||
return 0
|
||||
}
|
||||
|
||||
if MlrvalLessThanAsBool(value, (*array)[0]) {
|
||||
if BIF_less_than_as_bool(value, (*array)[0]) {
|
||||
return 0
|
||||
}
|
||||
if MlrvalGreaterThanAsBool(value, (*array)[hi]) {
|
||||
if BIF_greater_than_as_bool(value, (*array)[hi]) {
|
||||
return size
|
||||
}
|
||||
|
||||
for lo < hi {
|
||||
middleElement := (*array)[mid]
|
||||
if MlrvalEqualsAsBool(value, middleElement) {
|
||||
if BIF_equals_as_bool(value, middleElement) {
|
||||
return mid
|
||||
} else if MlrvalLessThanAsBool(value, middleElement) {
|
||||
} else if BIF_less_than_as_bool(value, middleElement) {
|
||||
hi = mid
|
||||
newmid = (hi + lo) / 2
|
||||
} else {
|
||||
|
|
@ -641,9 +641,9 @@ func BsearchMlrvalArrayForAscendingInsert(
|
|||
newmid = (hi + lo) / 2
|
||||
}
|
||||
if mid == newmid {
|
||||
if MlrvalLessThanOrEqualsAsBool(value, (*array)[lo]) {
|
||||
if BIF_less_than_or_equals_as_bool(value, (*array)[lo]) {
|
||||
return lo
|
||||
} else if MlrvalLessThanOrEqualsAsBool(value, (*array)[hi]) {
|
||||
} else if BIF_less_than_or_equals_as_bool(value, (*array)[hi]) {
|
||||
return hi
|
||||
} else {
|
||||
return hi + 1
|
||||
|
|
|
|||
23
todo.txt
23
todo.txt
|
|
@ -4,6 +4,12 @@ PUNCHDOWN LIST
|
|||
* --ifs-regex & --ips-regex -- guessing is not safe as evidence by '.' and '|'
|
||||
* JIT next:
|
||||
o mlrmap copy
|
||||
o krepl miller6 new doclink-comments
|
||||
|
||||
* perf next:
|
||||
o batchify source-quench
|
||||
! hash-records back off
|
||||
? further channelize (CSV-first focus) mlrval infer vs record-put ?
|
||||
|
||||
* big-picture item @ Rmd (csv memes; and beyond); also webdoc intro page
|
||||
|
||||
|
|
@ -100,8 +106,9 @@ PUNCHDOWN LIST
|
|||
----------------------------------------------------------------
|
||||
* JIT refactor
|
||||
o x 'tens/dozens of UT cases'
|
||||
o populate each bifs/X_test.go for each bifs/X.go from existing regression-test data
|
||||
m internal/pkg/mlrval
|
||||
- UT-driven mlrval defer/infer
|
||||
k UT-driven mlrval defer/infer
|
||||
- pkg/mlrval doc.go & README.md
|
||||
o internal/pkg/types
|
||||
k UT-driven mlrmap constructor refactor
|
||||
|
|
@ -112,9 +119,8 @@ PUNCHDOWN LIST
|
|||
mlrmap.PutReference(key, value)
|
||||
|
||||
k UT-driven DKVP-from-line
|
||||
- UT-driven X-from-line: nidx, xtab, csvlite, csv
|
||||
- UT-driven JSON-from-line
|
||||
- defer channelizers to a separate PR
|
||||
~ UT-driven X-from-line: nidx, xtab, csvlite, csv
|
||||
- UT-driven JSON-from-string
|
||||
o internal/pkg/output
|
||||
- basic
|
||||
mlrval.String()
|
||||
|
|
@ -145,17 +151,16 @@ PUNCHDOWN LIST
|
|||
----------------------------------------------------------------
|
||||
|
||||
* perf more
|
||||
o see other branch
|
||||
o nim6 note on perf: baseline/cat; processor/pipelining;
|
||||
o update https://miller.readthedocs.io/en/latest/cpu/, and/or
|
||||
https://miller.readthedocs.io/en/latest/streaming-and-memory/, and/or
|
||||
make a new page w/ info on per
|
||||
o JIT: maasure
|
||||
o pipelined reader
|
||||
o batched reader separately
|
||||
o buffered output
|
||||
k pipelined reader
|
||||
k batched reader separately
|
||||
k buffered output
|
||||
o re-check hashed/unhashed and do so periodically
|
||||
- env-var back door
|
||||
- CLI switch
|
||||
- check with more than just abixy
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue