Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Common/sorting.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415/*16in-place insertion sort for small arrays of data. This is O(n) if17already sorted and O(n^2) for worst case (elements are reversed)18sort order is smallest first19*/20void insertion_sort_uint16(uint16_t *data, uint16_t n);2122/*23remove duplicates from a sorted uint16_t array, returning the new24count25*/26uint16_t remove_duplicates_uint16(uint16_t *data, uint16_t n);2728/*29bisection search on a sorted uint16_t array to find an element30return true if found31*/32bool bisect_search_uint16(const uint16_t *data, uint16_t n, uint16_t value);3334/*35remove elements in a 2nd sorted array from a sorted uint16_t array36return the number of remaining elements37*/38uint16_t remove_list_uint16(uint16_t *data, uint16_t n, const uint16_t *rem, uint16_t n2);3940/*41return number of common elements between two sorted uint16_t lists42*/43uint16_t common_list_uint16(uint16_t *data, uint16_t n, const uint16_t *rem, uint16_t n2);444546