dist/src/SortedDictionary.js
/**Internal method to sort the dictionary by its keys or values
     *
     * @param byKey If true, the dictionary will be sorted by key, otherwise ba value
     * @param sortFunction Optional comparison function
     * @throws Throws an error if no suitable sorting function could be found for the type of the keys or values
     */
Internal method to sort the dictionary by its keys or values
@param byKey If true, the dictionary will be sorted by key, otherwise ba value
@param sortFunction Optional comparison function
@throws Throws an error if no suitable sorting function could be found for the type of the keys or values
Internal method to sort the dictionary by its keys or values @param byKey If true the dictionary will be sorted by key otherwise ba value @param sortFunction Optional comparison function @throws Throws an error if no suitable sorting function could be found for the type of the keys or values
sortInternal(byKey, sortFunction) {
        if (this.length === 0) {
            return;
        }
        var data = new Array(this.length);
        let i = 0;
        this.forEach(item => {
            if (byKey) {
                data[i] = new KeyValuePair(item.key, item.value);
            }
            else {
                data[i] = new KeyValuePair(item.value, item.key);
            }
            i++;
        });
        let kLen = data.length;
        let qSort;
        if (byKey) {
            qSort = new Sorter(data[0], true); 
        }
        else {
            qSort = new Sorter(data[0], true); 
        }
        //let qSort: Sorter<K> = new Sorter<K>(keys[0] as K); 
        if (sortFunction !== undefined) {
            qSort.sortTupleByFunction(sortFunction, data, 0, kLen);
        }
        else {
            if (qSort.hasCompareToImplemented === true) {
                qSort.sortTupleByImplementation(data, 0, kLen);
            }
            else if (qSort.isCommonType === true) {
                qSort.sortTupleByDefault(data, 0, kLen);
            }
            else {
                if (byKey) {
                    throw new Error("No suitable comparison method (a<>b) was found to sort by key (a<b:-1; a==b;0 a>b: 1)");
                }
                else {
                    throw new Error("No suitable comparison method (a<>b) was found to sort by value (a<b:-1; a==b;0 a>b: 1)");
                }
            }
        }
        this.clear();
        for (let i = 0; i < kLen; i++) {
            if (byKey) {
                this.add(data[i].key, data[i].value);
            }
            else {
                this.add(data[i].value, data[i].key);
            }
        }
    }
sortInternal ( byKey , sortFunction ) { if ( this . length === 0 ) { return ; } var data = new Array ( this . length ) ; let i = 0 ; this . forEach ( item => { if ( byKey ) { data [ i ] = new KeyValuePair ( item . key , item . value ) ; } else { data [ i ] = new KeyValuePair ( item . value , item . key ) ; } i ++ ; } ) ; let kLen = data . length ; let qSort ; if ( byKey ) { qSort = new Sorter ( data [ 0 ] , true ) ; } else { qSort = new Sorter ( data [ 0 ] , true ) ; } if ( sortFunction !== undefined ) { qSort . sortTupleByFunction ( sortFunction , data , 0 , kLen ) ; } else { if ( qSort . hasCompareToImplemented === true ) { qSort . sortTupleByImplementation ( data , 0 , kLen ) ; } else if ( qSort . isCommonType === true ) { qSort . sortTupleByDefault ( data , 0 , kLen ) ; } else { if ( byKey ) { throw new Error ( "No suitable comparison method (a<>b) was found to sort by key (a<b:-1; a==b;0 a>b: 1)" ) ; } else { throw new Error ( "No suitable comparison method (a<>b) was found to sort by value (a<b:-1; a==b;0 a>b: 1)" ) ; } } } this . clear ( ) ; for ( let i = 0 ; i < kLen ; i ++ ) { if ( byKey ) { this . add ( data [ i ] . key , data [ i ] . value ) ; } else { this . add ( data [ i ] . value , data [ i ] . key ) ; } } }
Internal method to sort the dictionary by its keys or values
 @param byKey If true, the dictionary will be sorted by key, otherwise ba value
 @param sortFunction Optional comparison function
 @throws Throws an error if no suitable sorting function could be found for the type of the keys or values
Internal method to sort the dictionary by its keys or values @param byKey If true the dictionary will be sorted by key otherwise ba value @param sortFunction Optional comparison function @throws Throws an error if no suitable sorting function could be found for the type of the keys or values
// Pass the 1st object as sample for type checking // Pass the 1st object as sample for type checking //let qSort: Sorter<K> = new Sorter<K>(keys[0] as K); // Pass the 1st object as sample for type checking