Skip to content

Commit b913b5e

Browse files
authored
bump: go 1.19 and fix: fmt issues (TheAlgorithms#519)
1 parent 14aa194 commit b913b5e

13 files changed

+40
-35
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
go: 1.18
2+
go: 1.19
33
linters:
44
disable:
55
- gosimple

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/TheAlgorithms/Go
22

3-
go 1.18
3+
go 1.19

graph/articulationpoints.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func ArticulationPoint(graph *Graph) []bool {
5050
// articulationPointHelper is a recursive function to traverse the graph
5151
// and mark articulation points. Based on the depth first search transversal
5252
// of the graph, however modified to keep track and update the
53-
// `child_cnt`, `discovery_time`` and `earliest_discovery` slices defined above
53+
// `child_cnt`, `discovery_time` and `earliest_discovery` slices defined above
5454
func articulationPointHelper(
5555
apHelperInstance *apHelper,
5656
vertex int,

graph/floydwarshall_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77

88
const float64EqualityThreshold = 1e-9
99

10-
//almostEqual subtracts two float64 variables and returns true if they differ less then float64EqualityThreshold
11-
//reference: https://stackoverflow.com/a/47969546
10+
// almostEqual subtracts two float64 variables and returns true if they differ less then float64EqualityThreshold
11+
// reference: https://stackoverflow.com/a/47969546
1212
func almostEqual(a, b float64) bool {
1313
return math.Abs(a-b) <= float64EqualityThreshold
1414
}
1515

16-
//IsAlmostEqualTo verifies if two WeightedGraphs can be considered almost equal
16+
// IsAlmostEqualTo verifies if two WeightedGraphs can be considered almost equal
1717
func (a *WeightedGraph) IsAlmostEqualTo(b WeightedGraph) bool {
1818
if len(*a) != len(b) {
1919
return false

math/binary/checkisnumberpoweroftwo.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ package binary
1111
// like 10...0 in binary, and numbers one less than the power of 2
1212
// are represented like 11...1.
1313
// Therefore, using the and function:
14-
// 10...0
15-
// & 01...1
16-
// 00...0 -> 0
14+
//
15+
// 10...0
16+
// & 01...1
17+
// 00...0 -> 0
18+
//
1719
// This is also true for 0, which is not a power of 2, for which we
1820
// have to add and extra condition.
1921
func IsPowerOfTwo(x int) bool {

math/pythagoras/pythagoras.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"math"
55
)
66

7-
//Vector defines a tuple with 3 values in 3d-space
7+
// Vector defines a tuple with 3 values in 3d-space
88
type Vector struct {
99
x float64
1010
y float64
1111
z float64
1212
}
1313

14-
//Distance calculates the distance between to vectors with the Pythagoras theorem
14+
// Distance calculates the distance between to vectors with the Pythagoras theorem
1515
func Distance(a, b Vector) float64 {
1616
res := math.Pow(b.x-a.x, 2.0) + math.Pow(b.y-a.y, 2.0) + math.Pow(b.z-a.z, 2.0)
1717
return math.Sqrt(res)

math/pythagoras/pythagoras_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var distanceTest = []struct {
1818
{"random short vectors", Vector{1, 1, 1}, Vector{2, 2, 2}, 1.73},
1919
}
2020

21-
//TestDistance tests the Function Distance with 2 vectors
21+
// TestDistance tests the Function Distance with 2 vectors
2222
func TestDistance(t *testing.T) {
2323
t.Parallel() // marks TestDistance as capable of running in parallel with other tests
2424
for _, tt := range distanceTest {

other/nested/nestedbrackets.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ package nested
88
//
99
// A sequence of brackets `s` is considered properly nested
1010
// if any of the following conditions are true:
11-
// - `s` is empty;
12-
// - `s` has the form (U) or [U] or {U} where U is a properly nested string;
13-
// - `s` has the form VW where V and W are properly nested strings.
11+
// - `s` is empty;
12+
// - `s` has the form (U) or [U] or {U} where U is a properly nested string;
13+
// - `s` has the form VW where V and W are properly nested strings.
1414
//
1515
// For example, the string "()()[()]" is properly nested but "[(()]" is not.
1616
//

search/binary.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func BinaryIterative(array []int, target int) (int, error) {
3737
return -1, ErrNotFound
3838
}
3939

40-
//Returns index to the first element in the range [0, len(array)-1] that is not less than (i.e. greater or equal to) target.
41-
//return -1 and ErrNotFound if no such element is found.
40+
// Returns index to the first element in the range [0, len(array)-1] that is not less than (i.e. greater or equal to) target.
41+
// return -1 and ErrNotFound if no such element is found.
4242
func LowerBound(array []int, target int) (int, error) {
4343
startIndex := 0
4444
endIndex := len(array) - 1
@@ -59,8 +59,8 @@ func LowerBound(array []int, target int) (int, error) {
5959
return startIndex, nil
6060
}
6161

62-
//Returns index to the first element in the range [lowIndex, len(array)-1] that is greater than target.
63-
//return -1 and ErrNotFound if no such element is found.
62+
// Returns index to the first element in the range [lowIndex, len(array)-1] that is greater than target.
63+
// return -1 and ErrNotFound if no such element is found.
6464
func UpperBound(array []int, target int) (int, error) {
6565
startIndex := 0
6666
endIndex := len(array) - 1

search/interpolation.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ package search
44
// if the entity is present, it will return the index of the entity, if not -1 will be returned.
55
// see: https://en.wikipedia.org/wiki/Interpolation_search
66
// Complexity
7-
// Worst: O(N)
8-
// Average: O(log(log(N)) if the elements are uniformly distributed
9-
// Best: O(1)
7+
//
8+
// Worst: O(N)
9+
// Average: O(log(log(N)) if the elements are uniformly distributed
10+
// Best: O(1)
11+
//
1012
// Example
11-
// fmt.Println(InterpolationSearch([]int{1, 2, 9, 20, 31, 45, 63, 70, 100},100))
13+
//
14+
// fmt.Println(InterpolationSearch([]int{1, 2, 9, 20, 31, 45, 63, 70, 100},100))
1215
func Interpolation(sortedData []int, guess int) (int, error) {
1316
if len(sortedData) == 0 {
1417
return -1, ErrNotFound

structure/segmenttree/segmenttree.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313

1414
const emptyLazyNode = 0
1515

16-
//SegmentTree with original Array and the Segment Tree Array
16+
// SegmentTree with original Array and the Segment Tree Array
1717
type SegmentTree struct {
1818
Array []int
1919
SegmentTree []int
2020
LazyTree []int
2121
}
2222

23-
//Propagate lazy tree node values
23+
// Propagate lazy tree node values
2424
func (s *SegmentTree) Propagate(node int, leftNode int, rightNode int) {
2525
if s.LazyTree[node] != emptyLazyNode {
2626
//add lazy node value multiplied by (right-left+1), which represents all interval
@@ -42,8 +42,8 @@ func (s *SegmentTree) Propagate(node int, leftNode int, rightNode int) {
4242
}
4343
}
4444

45-
//Query on interval [firstIndex, leftIndex]
46-
//node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
45+
// Query on interval [firstIndex, leftIndex]
46+
// node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
4747
func (s *SegmentTree) Query(node int, leftNode int, rightNode int, firstIndex int, lastIndex int) int {
4848
if (firstIndex > lastIndex) || (leftNode > rightNode) {
4949
//outside the interval
@@ -67,10 +67,10 @@ func (s *SegmentTree) Query(node int, leftNode int, rightNode int, firstIndex in
6767
return leftNodeSum + rightNodeSum
6868
}
6969

70-
//Update Segment Tree
71-
//node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
72-
//index is the Array index that you want to update
73-
//value is the value that you want to override
70+
// Update Segment Tree
71+
// node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
72+
// index is the Array index that you want to update
73+
// value is the value that you want to override
7474
func (s *SegmentTree) Update(node int, leftNode int, rightNode int, firstIndex int, lastIndex int, value int) {
7575
//propagate lazy tree
7676
s.Propagate(node, leftNode, rightNode)
@@ -96,8 +96,8 @@ func (s *SegmentTree) Update(node int, leftNode int, rightNode int, firstIndex i
9696
}
9797
}
9898

99-
//Build Segment Tree
100-
//node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
99+
// Build Segment Tree
100+
// node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
101101
func (s *SegmentTree) Build(node int, left int, right int) {
102102
if left == right {
103103
//leaf node

structure/segmenttree/segmenttree_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55
)
66

7-
//Query interval
7+
// Query interval
88
type query struct {
99
firstIndex int
1010
lastIndex int

structure/stack/stacklinkedlistwithlist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (sl *SList) Peak() (any, error) {
3434
}
3535

3636
// Pop is return last value that insert into our stack
37-
//also it will remove it in our stack
37+
// also it will remove it in our stack
3838
func (sl *SList) Pop() (any, error) {
3939
if !sl.Empty() {
4040
// get last element that insert into stack

0 commit comments

Comments
 (0)