Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Bin Sort [Go] #537

Merged
merged 6 commits into from
Oct 18, 2017
Merged

Added Bin Sort [Go] #537

merged 6 commits into from
Oct 18, 2017

Conversation

sergobot
Copy link
Contributor

Fixes #526

By submitting this pull request I confirm I've read and complied with the below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the coding guidelines for this project.
  • My code follows the skeleton code structure.
  • This pull request has a descriptive title. For example, Added {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.

@singhpratyush
Copy link
Member

Hi! Thanks for showing interest in contributing to this repository.

Please make sure that you have ticked the points mentioned in PR description correctly.

Thanks again!

@sergobot
Copy link
Contributor Author

The build failed due to Travis CI using older version of Go (<1.8). I'll update the code to use sort.Sort instead of sort.Slice.


import (
"fmt"
"math/rand"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type Bucket should have comment or be unexported

Origin: GoLintBear, Section: golint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@iiitv iiitv deleted a comment Oct 15, 2017
@iiitv iiitv deleted a comment Oct 15, 2017
Copy link
Member

@singhpratyush singhpratyush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is almost ready to merge. Please take a look at the comments.

// Methods required to allow sorting bucket's content
func (b Bucket) Len() int { return len(b) }
func (b Bucket) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b Bucket) Less(i, j int) bool { return b[i] < b[j] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please break these definitions in multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Do I need to expand to multiple lines or these single-line definitions are good to go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple lines would be good guess.

// Methods required to allow sorting bucket's content
func (b Bucket) Len() int { return len(b) }
func (b Bucket) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b Bucket) Less(i, j int) bool { return b[i] < b[j] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be less instead of Less? Same for Swap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort.Sort() requires these methods to be public (starting with capital letter)

type Bucket []float32

// Methods required to allow sorting bucket's content
func (b Bucket) Len() int { return len(b) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use len(b) directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we have to implement Len method, as it's required for sort.Sort().

)

// Bucket is used to store elements in BucketSort
type Bucket []float32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using global variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a global variable, it's a type alias. I made for the sake of easier understanding. I'll improve the comment to explain that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! Yes, I missed it. A comment would be good :)

@sergobot
Copy link
Contributor Author

I'll update the code later today.

@singhpratyush
Copy link
Member

@sergobot: Sure! Will be waiting :)

@sergobot
Copy link
Contributor Author

Weird. I just have committed changes to my fork but they don't show up here 😕

Copy link
Member

@mohitkyadav mohitkyadav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest looks fine.

sorted = append(sorted, buckets[i][j])
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

for i := range arr {
arr[i] = rand.Float32()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

@singhpratyush singhpratyush merged commit eb429ab into iiitv:master Oct 18, 2017
@singhpratyush
Copy link
Member

@sergobot: Thanks for the contribution :)

@sergobot
Copy link
Contributor Author

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bin Sort [Go]
4 participants