bytelist
File Name: bytelist.go
Overview
This file implements a byte list, which is a linked list where each node holds a byte array. It provides functionalities for creating, manipulating, and copying the byte list.
Detailed Documentation
byteListNodeSize
- Purpose: Stores the size of a
byteListNode
in bytes. - Type:
int64
init
- Purpose: Initializes the
byteListNodeSize
variable with the size of abyteListNode
struct.
byteList
- Purpose: Represents a linked list of byte arrays.
- Fields:
bufLen
: The initial capacity of the byte buffer in each node.size
: The total size in bytes of allbyteListNode
structs in the list.head
: A pointer to the first node in the list.tail
: A pointer to the last node in the list.
byteListNode
- Purpose: Represents a node in the byte list, containing a byte array and pointers to the next and previous nodes.
- Fields:
buf
: The byte array stored in the node.next
: A pointer to the next node in the list.prev
: A pointer to the previous node in the list.
newByteList
- Purpose: Creates a new
byteList
with the given buffer length. - Parameters:
bufLen
(int
): The initial capacity of the byte buffer in each node.
- Returns: A pointer to the newly created
byteList
.
func newByteList(bufLen int) *byteList
(b *byteList) newNode
- Purpose: Creates a new
byteListNode
with a byte buffer of initial capacityb.bufLen
. - Parameters: None
- Returns: A pointer to the newly created
byteListNode
.
func (b *byteList) newNode() *byteListNode
(b *byteList) newNodeWithCapacity
- Purpose: Creates a new
byteListNode
with a byte buffer of the given capacity. - Parameters:
capacity
(int
): The capacity of the byte buffer in the node.
- Returns: A pointer to the newly created
byteListNode
.
func (b *byteList) newNodeWithCapacity(capacity int) *byteListNode
(b *byteList) append
- Purpose: Appends a
byteListNode
to the end of thebyteList
. - Parameters:
bn
(*byteListNode
): The node to append.
- Returns: None
func (b *byteList) append(bn *byteListNode)
(b *byteList) prepend
- Purpose: Prepends a
byteListNode
to the beginning of thebyteList
. - Parameters:
bn
(*byteListNode
): The node to prepend.
- Returns: None
func (b *byteList) prepend(bn *byteListNode)
(b *byteList) delete
- Purpose: Deletes a
byteListNode
from thebyteList
. - Parameters:
bn
(*byteListNode
): The node to delete.
- Returns: None
func (b *byteList) delete(bn *byteListNode)
(b *byteList) DeepCopy
- Purpose: Creates a deep copy of the
byteList
. - Parameters: None
- Returns: A pointer to the new
byteList
copy.
func (b *byteList) DeepCopy() *byteList
(node *byteListNode) deepCopyNode
- Purpose: Recursively copies a
byteListNode
and its subsequent nodes. - Parameters:
prevCopy
(*byteListNode
): A pointer to the previous node in the copied list.
- Returns: A pointer to the copied
byteListNode
.
func (node *byteListNode) deepCopyNode(prevCopy *byteListNode) *byteListNode
Code Examples
None