Giter VIP home page Giter VIP logo

Comments (2)

eliaslevy avatar eliaslevy commented on July 22, 2024

Reading the tests it seems Values() and the iterator are not expected to be ordered. I got the opposite impression from the documentation. If that is the case, then there is bug. But it would be a lot more useful of the iterator returned items in the sort order.

from gods.

emirpasic avatar emirpasic commented on July 22, 2024

@eliaslevy

You are right that the values are not expected to be ordered in the way you expected it and that's exactly how a binary heap works: https://www.cs.cmu.edu/~adamchik/15-121/lectures/Binary%20Heaps/heaps.html

A binary heap is a complete binary tree which satisfies the heap ordering property. The ordering can be one of two types:

the min-heap property: the value of each node is greater than or equal to the value of its parent, with the minimum-value element at the root.
the max-heap property: the value of each node is less than or equal to the value of its parent, with the maximum-value element at the root.

In case you need to sort them, you can sort them manually using: https://github.com/emirpasic/gods#sort

Otherwise, if you'd like the data structure to keep the elements sorted, then you probably would like to use some other type of data structure, e.g. TreeSet https://github.com/emirpasic/gods#treeset

Cheers

from gods.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.