 ;; with this HEAP-SORT becomes a pie @implementation
 ;;;;;;;;
 (set! *warn-on-reflection* true)
-(def nums (shuffle (range 0 10000)))
+(def nums (shuffle (range 0 100000)))
 nums
 
 (time

;; i've used ArrayList in my heap-insert/heap-extract implementations relying on
;; dynamic shrinking the array-list while removing items from it, however behind
;; the scenes, the entire array is copied with System.arraycopy...which is NOT
;; wise at all...

;; own thoughts...on how to improve the performance
;; to optimize the heapify operation, i should discard ALL the ((2^height - 1) level) items
;; bubbling-up, because those are leafs and shouldn't by heap-ordered!
;; therefore:: based on the .length of the array, i should find the 
;; correspondent:: 2^x factor. i'm interested in finding the "x" here...
;; where the x stands for the height, if i know the height, i know which items
;; should be discarded based on the total items
;; applying Math here, i'm interested in finding the (log2 x) by applying the
;; (log10 x) / (log10 2) -> gives the logarithm in base 2
(/ (Math/log10 8) (Math/log10 2)) ;; => (log2 x) -> where x = 3
(/ (Math/log10 11) (Math/log10 2)) ;; => (log2 x) -> where x = 3.4594316186372978
;; -> so flooring the number and i got the height
;; if the items in an array size is: 11 -> then we can apply the math formula,
;; and get the height, then applying the power of 2 using that computed height
;; i know the range of the items that SHOULD BE included in the heap operation.

(defn heapify [xs]
  "heapify takes a vector and transforms it into a heapified data-structure
   the operations performs in O(nlogn) just like any sorting operation
   Note:: there's no better sorting operation that performs faster than

  (def s (heap-sort-by-heapify nums)))
s

;;;;;;;;;;;;;;;
;; ANALYSING & IMPROVING the running times.....
;;;;;;;;;;;;;;;
(time
  (def a (reduce (fn [acc x] (.add acc x) acc) (ArrayList.) (range 0 100000))))
;; producing a new ArrayList with 100K items requires:: "Elapsed time: 142.279817 msecs"
