當前位置: 首頁>>代碼示例>>Golang>>正文


Golang tsm1.FloatDecoder類代碼示例

本文整理匯總了Golang中github.com/influxdata/influxdb/tsdb/engine/tsm1.FloatDecoder的典型用法代碼示例。如果您正苦於以下問題:Golang FloatDecoder類的具體用法?Golang FloatDecoder怎麽用?Golang FloatDecoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FloatDecoder類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestFloatDecoder_Empty

func TestFloatDecoder_Empty(t *testing.T) {
	var dec tsm1.FloatDecoder
	if err := dec.SetBytes([]byte{}); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if dec.Next() {
		t.Fatalf("exp next == false, got true")
	}
}
開發者ID:jsternberg,項目名稱:influxdb,代碼行數:10,代碼來源:float_test.go

示例2: BenchmarkFloatDecoder

func BenchmarkFloatDecoder(b *testing.B) {
	s := tsm1.NewFloatEncoder()
	for _, tt := range TwoHoursData {
		s.Push(tt.v)
	}
	s.Finish()
	bytes, err := s.Bytes()
	if err != nil {
		b.Fatalf("unexpected error: %v", err)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		var it tsm1.FloatDecoder
		if err := it.SetBytes(bytes); err != nil {
			b.Fatalf("unexpected error creating float decoder: %v", err)
		}

		for j := 0; j < len(TwoHoursData); it.Next() {
			j++
		}
	}
}
開發者ID:ChenXiukun,項目名稱:influxdb,代碼行數:24,代碼來源:float_test.go

示例3: Test_FloatEncoder_Quick

func Test_FloatEncoder_Quick(t *testing.T) {
	quick.Check(func(values []float64) bool {

		expected := values
		if values == nil {
			expected = []float64{}
		}

		// Write values to encoder.
		enc := tsm1.NewFloatEncoder()
		for _, v := range values {
			enc.Push(v)
		}
		enc.Finish()

		// Read values out of decoder.
		got := make([]float64, 0, len(values))
		b, err := enc.Bytes()
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}

		var dec tsm1.FloatDecoder
		if err := dec.SetBytes(b); err != nil {
			t.Fatal(err)
		}
		for dec.Next() {
			got = append(got, dec.Values())
		}

		// Verify that input and output values match.
		if !reflect.DeepEqual(expected, got) {
			t.Fatalf("mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", expected, got)
		}

		return true
	}, nil)
}
開發者ID:ChenXiukun,項目名稱:influxdb,代碼行數:38,代碼來源:float_test.go

示例4: TestFloatEncoder_SimilarFloats

func TestFloatEncoder_SimilarFloats(t *testing.T) {
	s := tsm1.NewFloatEncoder()
	want := []float64{
		6.00065e+06,
		6.000656e+06,
		6.000657e+06,

		6.000659e+06,
		6.000661e+06,
	}

	for _, v := range want {
		s.Push(v)
	}

	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	for _, w := range want {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		if w != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}
開發者ID:ChenXiukun,項目名稱:influxdb,代碼行數:45,代碼來源:float_test.go

示例5: TestFloatEncoder_Roundtrip

func TestFloatEncoder_Roundtrip(t *testing.T) {
	s := tsm1.NewFloatEncoder()
	for _, p := range TwoHoursData {
		s.Push(p.v)
	}
	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	for _, w := range TwoHoursData {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		// t.Logf("it.Values()=(%+v, %+v)\n", time.Unix(int64(tt), 0), vv)
		if w.v != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w.v)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}
開發者ID:ChenXiukun,項目名稱:influxdb,代碼行數:36,代碼來源:float_test.go

示例6: TestFloatEncoder_Simple

func TestFloatEncoder_Simple(t *testing.T) {
	// Example from the paper
	s := tsm1.NewFloatEncoder()

	s.Push(12)
	s.Push(12)
	s.Push(24)

	// extra tests

	// floating point masking/shifting bug
	s.Push(13)
	s.Push(24)

	// delta-of-delta sizes
	s.Push(24)
	s.Push(24)
	s.Push(24)

	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	want := []float64{
		12,
		12,
		24,

		13,
		24,

		24,
		24,
		24,
	}

	for _, w := range want {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		if w != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}
開發者ID:ChenXiukun,項目名稱:influxdb,代碼行數:62,代碼來源:float_test.go


注:本文中的github.com/influxdata/influxdb/tsdb/engine/tsm1.FloatDecoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。