Uploaded image for project: 'Apache Apex Malhar'
  1. Apache Apex Malhar
  2. APEXMALHAR-24

Another Bug in offer(E e) function of com.datatorrent.lib.util.TopNSort.java

Details

    • Task
    • Status: Closed
    • Resolution: Fixed
    • None
    • 0.3.4
    • None
    • None

    Description

      In the current implementation offer(E e) of TopNSort.java

      @SuppressWarnings("unchecked")
      public boolean offer(E e)
      {
      if (q.size() <= qbound) {
      return q.offer(e);
      }

      boolean ret = true;
      boolean insert;
      Comparable<? super E> head = (Comparable<? super E>)q.peek();

      if (ascending) { // means head is the lowest value due to inversion
      insert = head.compareTo(e) <= 0; // e >= head
      }
      else { // means head is the highest value due to inversion
      insert = head.compareTo(e) >= 0; // head is <= e
      }
      if (insert && q.offer(e)) {
      ret = true;
      q.poll();
      }
      return ret;
      }

      In the 1st line the check should be made only for "<" not "<=" i.e. it should as following

      if (q.size() < qbound) {
      return q.offer(e);
      }

      For e.g. if you set qbound as 2, with current implementation you end up adding 3 elements in the queue

      Attachments

        Activity

          People

            chenar Chetan Narsude
            gaurav.gopi123 gaurav gupta
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment