support ascending and descending compare function