Skip to main content
typo.
Source Link
rolfl
  • 98.1k
  • 17
  • 220
  • 419

Just a few smaller issues:

  • Why expose buildHeap() when every other public method, including the constructors, already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefortherefore vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.
  • There is a getParent() helper, but you have omitted such helpers for getLeft() and getRight(), even though you are using the corresponding expressions multiple times.

Just a few smaller issues:

  • Why expose buildHeap() when every other public method, including the constructors, already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefor vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.
  • There is a getParent() helper, but you have omitted such helpers for getLeft() and getRight(), even though you are using the corresponding expressions multiple times.

Just a few smaller issues:

  • Why expose buildHeap() when every other public method, including the constructors, already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefore vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.
  • There is a getParent() helper, but you have omitted such helpers for getLeft() and getRight(), even though you are using the corresponding expressions multiple times.
added 177 characters in body
Source Link
Ext3h
  • 2.9k
  • 13
  • 17

Just a few smaller issues:

  • Why expose buildHeap() when every other public method, including the constructors, already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefor vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.
  • There is a getParent() helper, but you have omitted such helpers for getLeft() and getRight(), even though you are using the corresponding expressions multiple times.

Just a few smaller issues:

  • Why expose buildHeap() when every other public method already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefor vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.

Just a few smaller issues:

  • Why expose buildHeap() when every other public method, including the constructors, already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefor vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.
  • There is a getParent() helper, but you have omitted such helpers for getLeft() and getRight(), even though you are using the corresponding expressions multiple times.
Source Link
Ext3h
  • 2.9k
  • 13
  • 17

Just a few smaller issues:

  • Why expose buildHeap() when every other public method already leaves you with a perfectly sorted heap?
  • Why does the add() method contain sorting logic? This would usually be placed in an increment() method.
  • An increment() method is missing.
  • Your add() method did not copy the element. Your heap is therefor vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world.
  • Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
  • There is no interface to get the sorted list back.
  • The toString() method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order.
  • Please don't use it in production. Your basic MaxHeap has significantly worse runtime characteristics than the default Fibonacci Heap.