utils

package
v4.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLocalhostIP

func IsLocalhostIP(ipStr string) bool

IsLocalhostIP checks if the given IP address string (ipStr) is bound to any local network interface. It returns true if the IP is found on any interface, false otherwise. This function parses the input string as an IP address, iterates over all network interfaces on the host, and checks if any of the interface addresses match the target IP.

func ParseIP

func ParseIP(ip string) []string

ParseIP parses a CIDR, an IP range string (e.g., "xxx-xxx"), or a single IP into a slice of actual IPs. Supports both IPv4 and IPv6.

func ReadDirFiles

func ReadDirFiles(fsys fs.FS, dir string, handler func(data []byte) error) error

ReadDirFiles read all file in input fs and dir

func RemoveDuplicatesInOrder

func RemoveDuplicatesInOrder[T comparable](arr []T) []T

RemoveDuplicatesInOrder removes duplicate elements from a slice while preserving the original order. It works for any slice of comparable type T. Example: RemoveDuplicatesInOrder([]int{1,2,2,3}) returns []int{1,2,3}

Types

type KahnGraph

type KahnGraph struct {
	// contains filtered or unexported fields
}

KahnGraph represents a directed graph and provides efficient cycle detection using Kahn's algorithm. Kahn's algorithm repeatedly removes nodes with in-degree 0 (i.e., nodes with no dependencies). If a cycle exists, nodes in the cycle will never have in-degree 0, so the algorithm cannot process all nodes, thus detecting the presence of a cycle.

func NewKahnGraph

func NewKahnGraph() *KahnGraph

NewKahnGraph initializes and returns an empty KahnGraph.

func (*KahnGraph) AddEdgeAndCheckCycle

func (g *KahnGraph) AddEdgeAndCheckCycle(a, b string) bool

AddEdgeAndCheckCycle adds a directed edge from node a to node b and immediately checks if a cycle is formed. Parameters:

  • a: source node
  • b: target node

Returns:

  • true if adding the edge creates a cycle; false otherwise

Jump to

Keyboard shortcuts

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