Exemplo n.º 1
0
func encode(s string) []byte {
	switch *enc {
	case stringFormat:
		return []byte(s)
	case floatFormat:
		result, err := strconv.ParseFloat(s, 64)
		if err != nil {
			panic(err)
		}
		return setop.EncodeFloat64(result)
	case intFormat:
		result, err := strconv.ParseInt(s, 10, 64)
		if err != nil {
			panic(err)
		}
		return setop.EncodeInt64(result)
	case bigFormat:
		result, ok := new(big.Int).SetString(s, 10)
		if !ok {
			panic(fmt.Errorf("Bad BigInt format: %v", s))
		}
		return setop.EncodeBigInt(result)
	}
	panic(fmt.Errorf("Unknown encoding: %v", *enc))
}
Exemplo n.º 2
0
func testSetExpression(t *testing.T, c testClient) {
	t1 := []byte("sete1")
	t2 := []byte("sete2")
	for i := byte(0); i < 10; i++ {
		c.SubPut(t1, []byte{i}, setop.EncodeBigInt(big.NewInt(1)))
	}
	for i := byte(5); i < 15; i++ {
		c.SubPut(t2, []byte{i}, setop.EncodeBigInt(big.NewInt(1)))
	}
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Op: setop.MustParse("(U:BigIntAnd sete1 sete2)"),
	}), []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, []byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min: []byte{2},
		Max: []byte{6},
		Op:  setop.MustParse("(U:BigIntAnd sete1 sete2)"),
	}), []byte{3, 4, 5}, []byte{1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Op:     setop.MustParse("(U:BigIntAnd sete1 sete2)"),
	}), []byte{2, 3, 4, 5, 6}, []byte{1, 1, 1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Len:    3,
		Op:     setop.MustParse("(U:BigIntAnd sete1 sete2)"),
	}), []byte{2, 3, 4}, []byte{1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Len:    3,
		Dest:   []byte("sete3"),
		Op:     setop.MustParse("(U:BigIntAnd sete1 sete2)"),
	}), []byte{}, []byte{})
	min := 0
	max := 100
	assertItems(t, c.SliceIndex([]byte("sete3"), &min, &max), []byte{2, 3, 4}, []byte{1, 1, 1})

	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Code: "(U:BigIntAnd sete1 sete2)",
	}), []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, []byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:  []byte{2},
		Max:  []byte{6},
		Code: "(U:BigIntAnd sete1 sete2)",
	}), []byte{3, 4, 5}, []byte{1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Code:   "(U:BigIntAnd sete1 sete2)",
	}), []byte{2, 3, 4, 5, 6}, []byte{1, 1, 1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Len:    3,
		Code:   "(U:BigIntAnd sete1 sete2)",
	}), []byte{2, 3, 4}, []byte{1, 1, 1})
	assertSetOps(t, c.SetExpression(setop.SetExpression{
		Min:    []byte{2},
		Max:    []byte{6},
		MinInc: true,
		MaxInc: true,
		Len:    3,
		Dest:   []byte("sete4"),
		Code:   "(U:BigIntAnd sete1 sete2)",
	}), []byte{}, []byte{})
	assertItems(t, c.SliceIndex([]byte("sete4"), &min, &max), []byte{2, 3, 4}, []byte{1, 1, 1})
}