utils

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountFiles

func CountFiles(dir string, subfix string, skipdir string) (int, int)

count files and total size with specific subfix in a directory recursively

func CountLines

func CountLines(text string) []int

CountLines calculates the starting offsets of lines in a given text. Each offset marks the byte position of the character immediately following a newline character, or 0 for the very beginning of the text.

func CountLinesCached

func CountLinesCached(key string, text string) *[]int

The cached version of CountLines. Avoids redundant computations for the same text. Use when the same text is processed multiple times, such as contents of a file.

The key MUST uniquely identify the text i.e. for any two invocations

CountLinesCached(key1, text1) and CountLinesCached(key2, text2),

if key1 == key2, then text1 must be equal to text2 (and also vice versa).

func CountLinesPooled

func CountLinesPooled(text string) *[]int

The pooled version of CountLines. Eases burden on allocation and GC. Use when invocation on small text is frequent.

MUST manually invoke `PutCount` when done with the result to return the slice to the pool.

func DedupSlice

func DedupSlice[T comparable](s []T) []T

func FirstFile

func FirstFile(dir string, subfix string, skipdir string) string

find the first file with specific subfix in a directory recursively

func MustWriteFile

func MustWriteFile(fpath string, data []byte) error

func PutCount

func PutCount(count *[]int)

USE AND ONLY USE in pairs with CountLinesPooled.

func WrapError

func WrapError(err error, msg string, v ...interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL