Source File
queue.go
Belonging Package
internal/fuzz
// Copyright 2021 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package fuzz// queue holds a growable sequence of inputs for fuzzing and minimization.//// For now, this is a simple ring buffer// (https://en.wikipedia.org/wiki/Circular_buffer).//// TODO(golang.org/issue/46224): use a prioritization algorithm based on input// size, previous duration, coverage, and any other metrics that seem useful.type queue struct {// elems holds a ring buffer.// The queue is empty when begin = end.// The queue is full (until grow is called) when end = begin + N - 1 (mod N)// where N = cap(elems).elems []anyhead, len int}func ( *queue) () int {return len(.elems)}func ( *queue) () {:= .cap():= * 2if == 0 {= 8}:= make([]any, ):= .lenfor := 0; < ; ++ {[] = .elems[(.head+)%]}.elems =.head = 0}func ( *queue) ( any) {if .len+1 > .cap() {.grow()}:= (.head + .len) % .cap().elems[] =.len++}func ( *queue) () (any, bool) {if .len == 0 {return nil, false}:= .elems[.head].elems[.head] = nil.head = (.head + 1) % .cap().len--return , true}func ( *queue) () (any, bool) {if .len == 0 {return nil, false}return .elems[.head], true}func ( *queue) () {* = queue{}}
![]() |
The pages are generated with Golds v0.7.9-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |