Skip to content
New issue

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

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

Already on GitHub? # to your account

add top (?) that takes max #9

Open
dblock opened this issue Feb 12, 2011 · 2 comments
Open

add top (?) that takes max #9

dblock opened this issue Feb 12, 2011 · 2 comments

Comments

@dblock
Copy link

dblock commented Feb 12, 2011

Not sure if this is a good name for it. We do a lot of fetching an array from the top of the heap (priority queue).

def top(max)
  results = []
  while results.size < max and size > 0 do 
    results << pop 
  end
  results
end

If you think it's a good idea, I'll make a proper pull request with a UT.

@GarrisonJ
Copy link
Contributor

@dblock A good name for this might be take because it looks like this works same way as Array#take.

@dblock
Copy link
Author

dblock commented Jan 18, 2024

@GarrisonJ this is such an obvious and excellent answer, thank you

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants