From 2c716a88c4a90b80482d8f0d5901d8664c727584 Mon Sep 17 00:00:00 2001 From: huangqian Date: Fri, 12 Nov 2021 22:52:41 +0800 Subject: [PATCH] gring example function 1.New 2.Cap 3.Len --- container/gring/gring_z_example_test.go | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 container/gring/gring_z_example_test.go diff --git a/container/gring/gring_z_example_test.go b/container/gring/gring_z_example_test.go new file mode 100644 index 000000000..417df2306 --- /dev/null +++ b/container/gring/gring_z_example_test.go @@ -0,0 +1,58 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gring_test + +import ( + "fmt" + "github.com/gogf/gf/v2/container/gring" +) + +func ExampleNew() { + // Non concurrent safety + gring.New(10) + + // Concurrent safety + gring.New(10, true) + + // Output: +} + +func ExampleRing_Cap() { + r1 := gring.New(10) + for i := 0; i < 5; i++ { + r1.Set(i).Next() + } + fmt.Println("Cap:", r1.Cap()) + + r2 := gring.New(10, true) + for i := 0; i < 10; i++ { + r2.Set(i).Next() + } + fmt.Println("Cap:", r2.Cap()) + + // Output: + // Cap: 10 + // Cap: 10 +} + +func ExampleRing_Len() { + r1 := gring.New(10) + for i := 0; i < 5; i++ { + r1.Set(i).Next() + } + fmt.Println("Cap:", r1.Len()) + + r2 := gring.New(10, true) + for i := 0; i < 10; i++ { + r2.Set(i).Next() + } + fmt.Println("Cap:", r2.Len()) + + // Output: + // Cap: 5 + // Cap: 10 +}