Dataset Viewer
Auto-converted to Parquet Duplicate
repo
stringclasses
6 values
id
int64
0
371
target_function_prompt
stringlengths
258
11.6k
function_signature
stringlengths
258
11.6k
focal_code
stringlengths
258
11.6k
function_name
stringlengths
2
36
start_line
int64
3
1.61k
end_line
int64
23
1.64k
file_path
stringlengths
7
56
context
stringlengths
3.33k
9.15k
Go-master
0
func IsSubsequence(s string, t string) bool { if len(s) > len(t) { return false } if s == t { return true } if len(s) == 0 { return true } sIndex := 0 for tIndex := 0; tIndex < len(t); tIndex++ { if s[sIndex] == t[tIndex] { sIndex++ } if sIndex == len(s) { return true } } return false...
func IsSubsequence(s string, t string) bool { if len(s) > len(t) { return false } if s == t { return true } if len(s) == 0 { return true } sIndex := 0 for tIndex := 0; tIndex < len(t); tIndex++ { if s[sIndex] == t[tIndex] { sIndex++ } if sIndex == len(s) { return true } } return false...
func IsSubsequence(s string, t string) bool { if len(s) > len(t) { return false } if s == t { return true } if len(s) == 0 { return true } sIndex := 0 for tIndex := 0; tIndex < len(t); tIndex++ { if s[sIndex] == t[tIndex] { sIndex++ } if sIndex == len(s) { return true } } return false...
IsSubsequence
9
34
strings/issubsequence.go
#FILE: Go-master/structure/trie/trie.go ##CHUNK 1 } return r } // remove lazily a word from the Trie node, no node is actually removed. func (n *Node) remove(s string) { if len(s) == 0 { return } next, ok := n, false for _, c := range s { next, ok = next.children[c] if !ok { // word cannot be found - we...
Go-master
1
func IsIsogram(text string, order IsogramOrder) (bool, error) { if order < First || order > Third { return false, errors.New("Invalid isogram order provided") } text = strings.ToLower(text) text = strings.Join(strings.Fields(text), "") if hasDigit(text) || hasSymbol(text) { return false, errors.New("Cannot c...
func IsIsogram(text string, order IsogramOrder) (bool, error) { if order < First || order > Third { return false, errors.New("Invalid isogram order provided") } text = strings.ToLower(text) text = strings.Join(strings.Fields(text), "") if hasDigit(text) || hasSymbol(text) { return false, errors.New("Cannot c...
func IsIsogram(text string, order IsogramOrder) (bool, error) { if order < First || order > Third { return false, errors.New("Invalid isogram order provided") } text = strings.ToLower(text) text = strings.Join(strings.Fields(text), "") if hasDigit(text) || hasSymbol(text) { return false, errors.New("Cannot c...
IsIsogram
33
70
strings/isisogram.go
#FILE: Go-master/graph/cycle.go ##CHUNK 1 } } return allCycles } func (g Graph) findAllCyclesHelper(current int, all, visiting, visited map[int]struct{}) (bool, [][]int) { parents := [][]int{} delete(all, current) visiting[current] = struct{}{} neighbors := g.edges[current] for v := range neighbors { ...
Go-master
2
func GeneticString(target string, charmap []rune, conf *Conf) (*Result, error) { populationNum := conf.PopulationNum if populationNum == 0 { populationNum = 200 } selectionNum := conf.SelectionNum if selectionNum == 0 { selectionNum = 50 } // Verify if 'populationNum' s bigger than 'selectionNum' if popul...
func GeneticString(target string, charmap []rune, conf *Conf) (*Result, error) { populationNum := conf.PopulationNum if populationNum == 0 { populationNum = 200 } selectionNum := conf.SelectionNum if selectionNum == 0 { selectionNum = 50 } // Verify if 'populationNum' s bigger than 'selectionNum' if popul...
func GeneticString(target string, charmap []rune, conf *Conf) (*Result, error) { populationNum := conf.PopulationNum if populationNum == 0 { populationNum = 200 } selectionNum := conf.SelectionNum if selectionNum == 0 { selectionNum = 50 } // Verify if 'populationNum' s bigger than 'selectionNum' if popul...
GeneticString
70
196
strings/genetic/genetic.go
#FILE: Go-master/math/pi/montecarlopi.go ##CHUNK 1 } // splitInt takes an integer x and splits it within an integer slice of length n in the most uniform // way possible. // For example, splitInt(10, 3) will return []int{4, 3, 3}, nil func splitInt(x int, n int) ([]int, error) { if x < n { return nil, fmt.Errorf("x...
Go-master
3
func Distance(str1, str2 string, icost, scost, dcost int) int { row1 := make([]int, len(str2)+1) row2 := make([]int, len(str2)+1) for i := 1; i <= len(str2); i++ { row1[i] = i * icost } for i := 1; i <= len(str1); i++ { row2[0] = i * dcost for j := 1; j <= len(str2); j++ { if str1[i-1] == str2[j-1] { ...
func Distance(str1, str2 string, icost, scost, dcost int) int { row1 := make([]int, len(str2)+1) row2 := make([]int, len(str2)+1) for i := 1; i <= len(str2); i++ { row1[i] = i * icost } for i := 1; i <= len(str1); i++ { row2[0] = i * dcost for j := 1; j <= len(str2); j++ { if str1[i-1] == str2[j-1] { ...
func Distance(str1, str2 string, icost, scost, dcost int) int { row1 := make([]int, len(str2)+1) row2 := make([]int, len(str2)+1) for i := 1; i <= len(str2); i++ { row1[i] = i * icost } for i := 1; i <= len(str1); i++ { row2[0] = i * dcost for j := 1; j <= len(str2); j++ { if str1[i-1] == str2[j-1] { ...
Distance
9
41
strings/levenshtein/levenshteindistance.go
#FILE: Go-master/dynamic/dicethrow.go ##CHUNK 1 dp := make([][]int, m+1) for i := range dp { dp[i] = make([]int, sum+1) } for i := 1; i <= n; i++ { if i <= sum { dp[1][i] = 1 } } for i := 2; i <= m; i++ { for j := 1; j <= sum; j++ { for k := 1; k <= n; k++ { if j-k >= 0 { dp[i][j] += dp[i...
Go-master
4
func LongestPalindrome(s string) string { boundaries := makeBoundaries(s) b := make([]int, len(boundaries)) k := 0 index := 0 maxLen := 0 maxCenterSize := 0 for i := range b { if i < k { b[i] = min.Int(b[2*index-i], k-i) } else { b[i] = 1 } for i-b[i] >= 0 && i+b[i] < len(boundaries) && boundaries[...
func LongestPalindrome(s string) string { boundaries := makeBoundaries(s) b := make([]int, len(boundaries)) k := 0 index := 0 maxLen := 0 maxCenterSize := 0 for i := range b { if i < k { b[i] = min.Int(b[2*index-i], k-i) } else { b[i] = 1 } for i-b[i] >= 0 && i+b[i] < len(boundaries) && boundaries[...
func LongestPalindrome(s string) string { boundaries := makeBoundaries(s) b := make([]int, len(boundaries)) k := 0 index := 0 maxLen := 0 maxCenterSize := 0 for i := range b { if i < k { b[i] = min.Int(b[2*index-i], k-i) } else { b[i] = 1 } for i-b[i] >= 0 && i+b[i] < len(boundaries) && boundaries[...
LongestPalindrome
36
62
strings/manacher/longestpalindrome.go
#FILE: Go-master/strings/search/boyermoore.go ##CHUNK 1 skip := 0 jump := n for i := 0; i < l-n+1; { skip = skips[jump] for k := n - 1; k > -1; k-- { if text[i+k] != pattern[k] { jump, ok := bcr[text[i+k]] if !ok { jump = n } i += jump break } if k == n-jump { k -= skip ...
Go-master
5
func horspool(t, p []rune) (int, error) { shiftMap := computeShiftMap(t, p) pos := 0 for pos <= len(t)-len(p) { if isMatch(pos, t, p) { return pos, nil } if pos+len(p) >= len(t) { // because the remaining length of the input string // is the same as the length of the pattern // and it does not matc...
func horspool(t, p []rune) (int, error) { shiftMap := computeShiftMap(t, p) pos := 0 for pos <= len(t)-len(p) { if isMatch(pos, t, p) { return pos, nil } if pos+len(p) >= len(t) { // because the remaining length of the input string // is the same as the length of the pattern // and it does not matc...
func horspool(t, p []rune) (int, error) { shiftMap := computeShiftMap(t, p) pos := 0 for pos <= len(t)-len(p) { if isMatch(pos, t, p) { return pos, nil } if pos+len(p) >= len(t) { // because the remaining length of the input string // is the same as the length of the pattern // and it does not matc...
horspool
15
36
strings/horspool/horspool.go
#FILE: Go-master/strings/bom/bom.go ##CHUNK 1 // currentOcc := 0 // pos = 0 // if debugMode == true { // fmt.Printf("\n\nWe are reading backwards in %q, searching for %q\n\nat position %d:\n", t, p, pos+m-1) // } // for pos <= n-m { // current = 0 //initial state of the oracle // j = m // for j > 0 && stat...
Go-master
6
func ConstructTrie(p []string) (trie map[int]map[uint8]int, stateIsTerminal []bool, f map[int][]int) { trie = make(map[int]map[uint8]int) stateIsTerminal = make([]bool, 1) f = make(map[int][]int) state := 1 CreateNewState(0, trie) for i := 0; i < len(p); i++ { current := 0 j := 0 for j < len(p[i]) && GetTra...
func ConstructTrie(p []string) (trie map[int]map[uint8]int, stateIsTerminal []bool, f map[int][]int) { trie = make(map[int]map[uint8]int) stateIsTerminal = make([]bool, 1) f = make(map[int][]int) state := 1 CreateNewState(0, trie) for i := 0; i < len(p); i++ { current := 0 j := 0 for j < len(p[i]) && GetTra...
func ConstructTrie(p []string) (trie map[int]map[uint8]int, stateIsTerminal []bool, f map[int][]int) { trie = make(map[int]map[uint8]int) stateIsTerminal = make([]bool, 1) f = make(map[int][]int) state := 1 CreateNewState(0, trie) for i := 0; i < len(p); i++ { current := 0 j := 0 for j < len(p[i]) && GetTra...
ConstructTrie
3
35
strings/ahocorasick/shared.go
#FILE: Go-master/strings/ahocorasick/advancedahocorasick.go ##CHUNK 1 stateIsTerminal[current] = true f[current] = ArrayUnion(f[current], f[s[current]]) //F(Current) <- F(Current) union F(S(Current)) } } else { s[current] = i //initial state? } } a := ComputeAlphabet(p) // concat of all patterns in ...
Go-master
7
func Advanced(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f := BuildExtendedAc(p) current := 0 for pos := 0; pos < len(t); pos++ { if GetTransition(current, t[pos], ac) != -1 { current = GetTransition(current, t[pos], ac) } else { current = 0 } _, ok ...
func Advanced(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f := BuildExtendedAc(p) current := 0 for pos := 0; pos < len(t); pos++ { if GetTransition(current, t[pos], ac) != -1 { current = GetTransition(current, t[pos], ac) } else { current = 0 } _, ok ...
func Advanced(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f := BuildExtendedAc(p) current := 0 for pos := 0; pos < len(t); pos++ { if GetTransition(current, t[pos], ac) != -1 { current = GetTransition(current, t[pos], ac) } else { current = 0 } _, ok ...
Advanced
9
42
strings/ahocorasick/advancedahocorasick.go
#FILE: Go-master/strings/ahocorasick/ahocorasick.go ##CHUNK 1 if ok { for i := range f[current] { if p[f[current][i]] == GetWord(pos-len(p[f[current][i]])+1, pos, t) { //check for word match newOccurrences := IntArrayCapUp(occurrences[f[current][i]]) occurrences[f[current][i]] = newOccurrences o...
Go-master
8
func BuildExtendedAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s := make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(state...
func BuildExtendedAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s := make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(state...
func BuildExtendedAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s := make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(state...
BuildExtendedAc
45
81
strings/ahocorasick/advancedahocorasick.go
#FILE: Go-master/strings/ahocorasick/ahocorasick.go ##CHUNK 1 } // Functions that builds Aho Corasick automaton. func BuildAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int, s []int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s = make([]int, len(stateIsTerminal)) //supply function i := 0 ...
Go-master
9
func AhoCorasick(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f, s := BuildAc(p) current := 0 for pos := 0; pos < len(t); pos++ { for GetTransition(current, t[pos], ac) == -1 && s[current] != -1 { current = s[current] } if GetTransition(current, t[pos], ac)...
func AhoCorasick(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f, s := BuildAc(p) current := 0 for pos := 0; pos < len(t); pos++ { for GetTransition(current, t[pos], ac) == -1 && s[current] != -1 { current = s[current] } if GetTransition(current, t[pos], ac)...
func AhoCorasick(t string, p []string) Result { startTime := time.Now() occurrences := make(map[int][]int) ac, f, s := BuildAc(p) current := 0 for pos := 0; pos < len(t); pos++ { for GetTransition(current, t[pos], ac) == -1 && s[current] != -1 { current = s[current] } if GetTransition(current, t[pos], ac)...
AhoCorasick
14
50
strings/ahocorasick/ahocorasick.go
#FILE: Go-master/strings/ahocorasick/advancedahocorasick.go ##CHUNK 1 startTime := time.Now() occurrences := make(map[int][]int) ac, f := BuildExtendedAc(p) current := 0 for pos := 0; pos < len(t); pos++ { if GetTransition(current, t[pos], ac) != -1 { current = GetTransition(current, t[pos], ac) } else { ...
Go-master
10
func BuildAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int, s []int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s = make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(stateI...
func BuildAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int, s []int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s = make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(stateI...
func BuildAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int, s []int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s = make([]int, len(stateIsTerminal)) //supply function i := 0 //root of acTrie acToReturn = acTrie s[i] = -1 for current := 1; current < len(stateI...
BuildAc
53
76
strings/ahocorasick/ahocorasick.go
#FILE: Go-master/strings/ahocorasick/advancedahocorasick.go ##CHUNK 1 resultOccurrences, } } // BuildExtendedAc Functions that builds extended Aho Corasick automaton. func BuildExtendedAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int) { acTrie, stateIsTerminal, f := ConstructTrie(p) s := make([]i...
Go-master
11
func HuffTree(listfreq []SymbolFreq) (*Node, error) { if len(listfreq) < 1 { return nil, fmt.Errorf("huffman coding: HuffTree : calling method with empty list of symbol-frequency pairs") } q1 := make([]Node, len(listfreq)) q2 := make([]Node, 0, len(listfreq)) for i, x := range listfreq { // after the loop, q1 is...
func HuffTree(listfreq []SymbolFreq) (*Node, error) { if len(listfreq) < 1 { return nil, fmt.Errorf("huffman coding: HuffTree : calling method with empty list of symbol-frequency pairs") } q1 := make([]Node, len(listfreq)) q2 := make([]Node, 0, len(listfreq)) for i, x := range listfreq { // after the loop, q1 is...
func HuffTree(listfreq []SymbolFreq) (*Node, error) { if len(listfreq) < 1 { return nil, fmt.Errorf("huffman coding: HuffTree : calling method with empty list of symbol-frequency pairs") } q1 := make([]Node, len(listfreq)) q2 := make([]Node, 0, len(listfreq)) for i, x := range listfreq { // after the loop, q1 is...
HuffTree
34
56
compression/huffmancoding.go
#FILE: Go-master/sqrt/sqrtdecomposition_test.go ##CHUNK 1 func(q1, q2 int) int { return q1 + q2 }, func(q, a, b int) int { return q - a + b }, ) for i := 0; i < len(test.updates); i++ { s.Update(test.updates[i].index, test.updates[i].value) } for i := 0; i < len(test.queries); i++ { result...
Go-master
12
func DepthFirstSearchHelper(start, end int, nodes []int, edges [][]bool, showroute bool) ([]int, bool) { var route []int var stack []int startIdx := GetIdx(start, nodes) stack = append(stack, startIdx) for len(stack) > 0 { now := stack[len(stack)-1] route = append(route, nodes[now]) if len(stack) > 1 { st...
func DepthFirstSearchHelper(start, end int, nodes []int, edges [][]bool, showroute bool) ([]int, bool) { var route []int var stack []int startIdx := GetIdx(start, nodes) stack = append(stack, startIdx) for len(stack) > 0 { now := stack[len(stack)-1] route = append(route, nodes[now]) if len(stack) > 1 { st...
func DepthFirstSearchHelper(start, end int, nodes []int, edges [][]bool, showroute bool) ([]int, bool) { var route []int var stack []int startIdx := GetIdx(start, nodes) stack = append(stack, startIdx) for len(stack) > 0 { now := stack[len(stack)-1] route = append(route, nodes[now]) if len(stack) > 1 { st...
DepthFirstSearchHelper
26
56
graph/depthfirstsearch.go
#FILE: Go-master/structure/tree/tree.go ##CHUNK 1 return searchTreeHelper(node.Left(), nilNode, key) } return searchTreeHelper(node.Right(), nilNode, key) } func inOrderHelper[T constraints.Ordered](node, nilNode Node[T]) []T { var stack []Node[T] var ret []T for node != nilNode || len(stack) > 0 { for node ...
Go-master
13
func EdmondKarp(graph WeightedGraph, source int, sink int) float64 { // Check graph emptiness if len(graph) == 0 { return 0.0 } // Check correct dimensions of the graph slice for i := 0; i < len(graph); i++ { if len(graph[i]) != len(graph) { return 0.0 } } rGraph := make(WeightedGraph, len(graph)) fo...
func EdmondKarp(graph WeightedGraph, source int, sink int) float64 { // Check graph emptiness if len(graph) == 0 { return 0.0 } // Check correct dimensions of the graph slice for i := 0; i < len(graph); i++ { if len(graph[i]) != len(graph) { return 0.0 } } rGraph := make(WeightedGraph, len(graph)) fo...
func EdmondKarp(graph WeightedGraph, source int, sink int) float64 { // Check graph emptiness if len(graph) == 0 { return 0.0 } // Check correct dimensions of the graph slice for i := 0; i < len(graph); i++ { if len(graph[i]) != len(graph) { return 0.0 } } rGraph := make(WeightedGraph, len(graph)) fo...
EdmondKarp
42
92
graph/edmondkarp.go
#FILE: Go-master/graph/floydwarshall.go ##CHUNK 1 } for i := 0; i < len(graph); i++ { //If graph matrix width is different than the height, returns nil if len(graph[i]) != len(graph) { return nil } } numVertices := len(graph) // Initializing result matrix and filling it up with same values as given gra...
Go-master
14
func BreadthFirstSearch(start, end, nodes int, edges [][]int) (isConnected bool, distance int) { queue := make([]int, 0) discovered := make([]int, nodes) discovered[start] = 1 queue = append(queue, start) for len(queue) > 0 { v := queue[0] queue = queue[1:] for i := 0; i < len(edges[v]); i++ { if discover...
func BreadthFirstSearch(start, end, nodes int, edges [][]int) (isConnected bool, distance int) { queue := make([]int, 0) discovered := make([]int, nodes) discovered[start] = 1 queue = append(queue, start) for len(queue) > 0 { v := queue[0] queue = queue[1:] for i := 0; i < len(edges[v]); i++ { if discover...
func BreadthFirstSearch(start, end, nodes int, edges [][]int) (isConnected bool, distance int) { queue := make([]int, 0) discovered := make([]int, nodes) discovered[start] = 1 queue = append(queue, start) for len(queue) > 0 { v := queue[0] queue = queue[1:] for i := 0; i < len(edges[v]); i++ { if discover...
BreadthFirstSearch
8
27
graph/breadthfirstsearch.go
#FILE: Go-master/graph/edmondkarp.go ##CHUNK 1 parent := make(map[int]int) // BFS loop with saving the path found for len(queue) > 0 { v := queue[0] queue = queue[1:] for i := 0; i < len(rGraph[v]); i++ { if !marked[i] && rGraph[v][i] > 0 { parent[i] = v // Terminate the BFS, if we reach to sink ...
Go-master
15
func FloydWarshall(graph WeightedGraph) WeightedGraph { // If graph is empty, returns nil if len(graph) == 0 || len(graph) != len(graph[0]) { return nil } for i := 0; i < len(graph); i++ { //If graph matrix width is different than the height, returns nil if len(graph[i]) != len(graph) { return nil } } ...
func FloydWarshall(graph WeightedGraph) WeightedGraph { // If graph is empty, returns nil if len(graph) == 0 || len(graph) != len(graph[0]) { return nil } for i := 0; i < len(graph); i++ { //If graph matrix width is different than the height, returns nil if len(graph[i]) != len(graph) { return nil } } ...
func FloydWarshall(graph WeightedGraph) WeightedGraph { // If graph is empty, returns nil if len(graph) == 0 || len(graph) != len(graph[0]) { return nil } for i := 0; i < len(graph); i++ { //If graph matrix width is different than the height, returns nil if len(graph[i]) != len(graph) { return nil } } ...
FloydWarshall
16
54
graph/floydwarshall.go
#FILE: Go-master/graph/edmondkarp.go ##CHUNK 1 } func EdmondKarp(graph WeightedGraph, source int, sink int) float64 { // Check graph emptiness if len(graph) == 0 { return 0.0 } // Check correct dimensions of the graph slice for i := 0; i < len(graph); i++ { if len(graph[i]) != len(graph) { return 0.0 } ...
Go-master
16
func KruskalMST(n int, edges []Edge) ([]Edge, int) { // Initialize variables to store the minimum spanning tree and its total cost var mst []Edge var cost int // Create a new UnionFind data structure with 'n' nodes u := NewUnionFind(n) // Sort the edges in non-decreasing order based on their weights sort.Slice...
func KruskalMST(n int, edges []Edge) ([]Edge, int) { // Initialize variables to store the minimum spanning tree and its total cost var mst []Edge var cost int // Create a new UnionFind data structure with 'n' nodes u := NewUnionFind(n) // Sort the edges in non-decreasing order based on their weights sort.Slice...
func KruskalMST(n int, edges []Edge) ([]Edge, int) { // Initialize variables to store the minimum spanning tree and its total cost var mst []Edge var cost int // Create a new UnionFind data structure with 'n' nodes u := NewUnionFind(n) // Sort the edges in non-decreasing order based on their weights sort.Slice...
KruskalMST
22
50
graph/kruskal.go
#FILE: Go-master/dynamic/optimalbst.go ##CHUNK 1 } // Total cost for root k cost := sum + leftCost + rightCost // Update dp[i][j] with the minimum cost dp[i][j] = min.Int(dp[i][j], cost) } } } return dp[0][n-1] } // Helper function to sum the frequencies func sum(freq []int, i, j int) int ...
Go-master
17
func NewTree(numbersVertex, root int, edges []TreeEdge) (tree *Tree) { tree = new(Tree) tree.numbersVertex, tree.root, tree.MAXLOG = numbersVertex, root, 0 tree.depth = make([]int, numbersVertex) tree.dad = make([]int, numbersVertex) for (1 << tree.MAXLOG) <= numbersVertex { (tree.MAXLOG) += 1 } (tree.MAXLOG)...
func NewTree(numbersVertex, root int, edges []TreeEdge) (tree *Tree) { tree = new(Tree) tree.numbersVertex, tree.root, tree.MAXLOG = numbersVertex, root, 0 tree.depth = make([]int, numbersVertex) tree.dad = make([]int, numbersVertex) for (1 << tree.MAXLOG) <= numbersVertex { (tree.MAXLOG) += 1 } (tree.MAXLOG)...
func NewTree(numbersVertex, root int, edges []TreeEdge) (tree *Tree) { tree = new(Tree) tree.numbersVertex, tree.root, tree.MAXLOG = numbersVertex, root, 0 tree.depth = make([]int, numbersVertex) tree.dad = make([]int, numbersVertex) for (1 << tree.MAXLOG) <= numbersVertex { (tree.MAXLOG) += 1 } (tree.MAXLOG)...
NewTree
85
107
graph/lowestcommonancestor.go
#FILE: Go-master/graph/lowestcommonancestor_test.go ##CHUNK 1 const MAXVERTEX int = 2000 var numbersVertex int = rnd.Intn(MAXVERTEX) + 1 var root int = rnd.Intn(numbersVertex) var edges []TreeEdge var fullGraph []TreeEdge for u := 0; u < numbersVertex; u++ { for v := 0; v < numbersVertex; v++ { fullGraph =...
Go-master
18
func Sign(m []byte, p, q, g, x *big.Int) (r, s *big.Int) { // 1. Choose a random integer k from the range [1, q-1] k, err := rand.Int(rand.Reader, new(big.Int).Sub(q, big.NewInt(1))) if err != nil { panic(err) } // 2. Compute r = (g^k mod p) mod q r = new(big.Int).Exp(g, k, p) r.Mod(r, q) // 3. Compute s = ...
func Sign(m []byte, p, q, g, x *big.Int) (r, s *big.Int) { // 1. Choose a random integer k from the range [1, q-1] k, err := rand.Int(rand.Reader, new(big.Int).Sub(q, big.NewInt(1))) if err != nil { panic(err) } // 2. Compute r = (g^k mod p) mod q r = new(big.Int).Exp(g, k, p) r.Mod(r, q) // 3. Compute s = ...
func Sign(m []byte, p, q, g, x *big.Int) (r, s *big.Int) { // 1. Choose a random integer k from the range [1, q-1] k, err := rand.Int(rand.Reader, new(big.Int).Sub(q, big.NewInt(1))) if err != nil { panic(err) } // 2. Compute r = (g^k mod p) mod q r = new(big.Int).Exp(g, k, p) r.Mod(r, q) // 3. Compute s = ...
Sign
124
148
cipher/dsa/dsa.go
#CURRENT FILE: Go-master/cipher/dsa/dsa.go ##CHUNK 1 // Sign is signature generation for DSA // 1. Choose a random integer k from the range [1, q-1] // 2. Compute r = (g^k mod p) mod q } // Verify is signature verification for DSA // 1. Compute w = s^-1 mod q // 2. Compute u1 = (H(m) * w) mod q // 3. Compute u2 = (r *...
Go-master
19
func Verify(m []byte, r, s, p, q, g, y *big.Int) bool { // 1. Compute w = s^-1 mod q w := new(big.Int).ModInverse(s, q) // 2. Compute u1 = (H(m) * w) mod q h := new(big.Int).SetBytes(m) // This should be the hash of the message u1 := new(big.Int).Mul(h, w) u1.Mod(u1, q) // 3. Compute u2 = (r * w) mod q u2 := ...
func Verify(m []byte, r, s, p, q, g, y *big.Int) bool { // 1. Compute w = s^-1 mod q w := new(big.Int).ModInverse(s, q) // 2. Compute u1 = (H(m) * w) mod q h := new(big.Int).SetBytes(m) // This should be the hash of the message u1 := new(big.Int).Mul(h, w) u1.Mod(u1, q) // 3. Compute u2 = (r * w) mod q u2 := ...
func Verify(m []byte, r, s, p, q, g, y *big.Int) bool { // 1. Compute w = s^-1 mod q w := new(big.Int).ModInverse(s, q) // 2. Compute u1 = (H(m) * w) mod q h := new(big.Int).SetBytes(m) // This should be the hash of the message u1 := new(big.Int).Mul(h, w) u1.Mod(u1, q) // 3. Compute u2 = (r * w) mod q u2 := ...
Verify
156
180
cipher/dsa/dsa.go
#FILE: Go-master/cipher/rsa/rsa2.go ##CHUNK 1 // returns the RSA object func New() *rsa { // The following code generates keys for RSA encryption/decryption // 1. Choose two large prime numbers, p and q and compute n = p * q p, q := randomPrime() // p and q stands for prime numbers modulus := p * q // n stands...
Go-master
20
func Encrypt(text string, rails int) string { if rails == 1 { return text } // Create a matrix for the rail fence pattern matrix := make([][]rune, rails) for i := range matrix { matrix[i] = make([]rune, len(text)) } // Fill the matrix dirDown := false row, col := 0, 0 for _, char := range text { if ro...
func Encrypt(text string, rails int) string { if rails == 1 { return text } // Create a matrix for the rail fence pattern matrix := make([][]rune, rails) for i := range matrix { matrix[i] = make([]rune, len(text)) } // Fill the matrix dirDown := false row, col := 0, 0 for _, char := range text { if ro...
func Encrypt(text string, rails int) string { if rails == 1 { return text } // Create a matrix for the rail fence pattern matrix := make([][]rune, rails) for i := range matrix { matrix[i] = make([]rune, len(text)) } // Fill the matrix dirDown := false row, col := 0, 0 for _, char := range text { if ro...
Encrypt
12
48
cipher/railfence/railfence.go
#FILE: Go-master/math/matrix/isvalid.go ##CHUNK 1 package matrix import "github.com/TheAlgorithms/Go/constraints" // IsValid checks if the input matrix has consistent row lengths. func IsValid[T constraints.Integer](elements [][]T) bool { if len(elements) == 0 { return true } columns := len(elements[0]) for _, ...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
3