utils

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileToDirectory

func AddFileToDirectory(root *Directory, filePath string)

AddFileToDirectory adds a file to the directory structure

func BasicEstimateTokenFromChars

func BasicEstimateTokenFromChars(charCount int) int

BasicEstimateTokenFromChars provides a simple estimate of tokens based on characters

func CountFilesRecursive

func CountFilesRecursive(dir *Directory) int

CountFilesRecursive counts the number of files in a directory and its subdirectories

func GenerateDotOutput

func GenerateDotOutput(root *Directory) string

GenerateDotOutput generates a DOT (Graphviz) representation of the directory tree

func GenerateJSONTreeOutput

func GenerateJSONTreeOutput(root *Directory) string

GenerateJSONTreeOutput generates a JSON representation of the directory tree

func GenerateTreeOutput

func GenerateTreeOutput(root *Directory) string

GenerateTreeOutput generates a string representation of the directory tree

func GenerateXMLTreeOutput

func GenerateXMLTreeOutput(root *Directory) string

GenerateXMLTreeOutput generates an XML representation of the directory tree

Types

type Directory

type Directory struct {
	Name    string
	SubDirs map[string]*Directory
	Files   []string
}

Directory represents a directory in the file system

func BuildTree

func BuildTree(files []string, rootName string) *Directory

BuildTree builds a directory tree from a list of files

func GetOrCreateDirectory

func GetOrCreateDirectory(parent *Directory, name string) *Directory

GetOrCreateDirectory gets or creates a directory at the specified path

func NewDirectory

func NewDirectory(name string) *Directory

NewDirectory creates a new directory structure

type TokenEstimator

type TokenEstimator struct {
	// Adjustment factors for different categories of text
	CodeFactor   float64
	TextFactor   float64
	SpecialChars map[rune]float64 // Special characters and their token weight
}

TokenEstimator estimates token counts from text

func NewTokenEstimator

func NewTokenEstimator() *TokenEstimator

NewTokenEstimator creates a new token estimator with default settings

func (*TokenEstimator) EstimateFileTokens

func (te *TokenEstimator) EstimateFileTokens(filePath string, isCode bool) (int, error)

EstimateFileTokens estimates the number of tokens in a file

func (*TokenEstimator) EstimateTokens

func (te *TokenEstimator) EstimateTokens(text string, isCode bool) int

EstimateTokens estimates the number of tokens in the given text The isCode parameter indicates whether the text is code or natural language

Jump to

Keyboard shortcuts

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