github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/container/queue/chunk.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package queue 15 16 type chunk[T any] struct { 17 // [l, r) is a left open right closed interval, 18 // that indicates invalid elements within the chunk 19 l int 20 r int 21 data []T 22 23 prev *chunk[T] 24 next *chunk[T] 25 26 // a pointer points to the queue 27 queue *ChunkQueue[T] 28 } 29 30 func (c *chunk[T]) empty() bool { 31 return c.l >= c.r 32 } 33 34 func (c *chunk[T]) len() int { 35 return c.r - c.l 36 } 37 38 func (c *chunk[T]) reset() { 39 c.l, c.r = 0, 0 40 c.prev, c.next, c.queue = nil, nil, nil 41 } 42 43 func newChunk[T any](size int, q *ChunkQueue[T]) *chunk[T] { 44 return &chunk[T]{ 45 data: make([]T, size), 46 queue: q, 47 } 48 }