Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsLocalhostIP ¶
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 ¶
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 ¶
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 ¶
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