mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Change bsearch C standard function by new lv_bsearch propietary function.
This commit is contained in:
parent
b882174bf9
commit
92b79cf3a8
@ -6,11 +6,10 @@
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "lv_font.h"
|
#include "lv_font.h"
|
||||||
#include "lv_log.h"
|
#include "lv_log.h"
|
||||||
|
#include "lv_math.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@ -24,7 +23,7 @@
|
|||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
static int lv_font_codeCompare (const void* pRef, const void* pElement);
|
static int32_t lv_font_codeCompare (const void* pRef, const void* pElement);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@ -222,7 +221,7 @@ const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unico
|
|||||||
|
|
||||||
uint32_t* pUnicode;
|
uint32_t* pUnicode;
|
||||||
|
|
||||||
pUnicode = bsearch(&unicode_letter,
|
pUnicode = lv_bsearch(&unicode_letter,
|
||||||
(uint32_t*) font->unicode_list,
|
(uint32_t*) font->unicode_list,
|
||||||
font->glyph_cnt,
|
font->glyph_cnt,
|
||||||
sizeof(uint32_t),
|
sizeof(uint32_t),
|
||||||
@ -266,7 +265,7 @@ int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter
|
|||||||
|
|
||||||
uint32_t* pUnicode;
|
uint32_t* pUnicode;
|
||||||
|
|
||||||
pUnicode = bsearch(&unicode_letter,
|
pUnicode = lv_bsearch(&unicode_letter,
|
||||||
(uint32_t*) font->unicode_list,
|
(uint32_t*) font->unicode_list,
|
||||||
font->glyph_cnt,
|
font->glyph_cnt,
|
||||||
sizeof(uint32_t),
|
sizeof(uint32_t),
|
||||||
@ -297,7 +296,7 @@ int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter
|
|||||||
* @retval > 0 Reference is less than element.
|
* @retval > 0 Reference is less than element.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int lv_font_codeCompare (const void* pRef,
|
static int32_t lv_font_codeCompare (const void* pRef,
|
||||||
const void* pElement)
|
const void* pElement)
|
||||||
{
|
{
|
||||||
return (*(uint32_t*) pRef) - (*(uint32_t*) pElement);
|
return (*(uint32_t*) pRef) - (*(uint32_t*) pElement);
|
||||||
|
@ -159,6 +159,49 @@ int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a binary search within the given list.
|
||||||
|
*
|
||||||
|
* @note Code extracted out of https://github.com/torvalds/linux/blob/master/lib/bsearch.c
|
||||||
|
*
|
||||||
|
* @warning The contents of the array should already be in ascending sorted order
|
||||||
|
* under the provided comparison function.
|
||||||
|
*
|
||||||
|
* @note The key need not have the same type as the elements in
|
||||||
|
* the array, e.g. key could be a string and the comparison function
|
||||||
|
* could compare the string with the struct's name field. However, if
|
||||||
|
* the key and elements in the array are of the same type, you can use
|
||||||
|
* the same comparison function for both sort() and bsearch().
|
||||||
|
*
|
||||||
|
* @param key pointer to item being searched for
|
||||||
|
* @param base pointer to first element to search
|
||||||
|
* @param num number of elements
|
||||||
|
* @param size size of each element
|
||||||
|
* @param cmp pointer to comparison function
|
||||||
|
*/
|
||||||
|
void * lv_bsearch(const void * key, const void * base, uint32_t num, uint32_t size, int32_t (* cmp)(const void * key, const void * elt))
|
||||||
|
{
|
||||||
|
const char * pivot;
|
||||||
|
int32_t result;
|
||||||
|
|
||||||
|
while (num > 0) {
|
||||||
|
pivot = ((char*)base) + (num >> 1) * size;
|
||||||
|
result = cmp(key, pivot);
|
||||||
|
|
||||||
|
if (result == 0)
|
||||||
|
return (void *)pivot;
|
||||||
|
|
||||||
|
if (result > 0) {
|
||||||
|
base = pivot + size;
|
||||||
|
num--;
|
||||||
|
}
|
||||||
|
num >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -62,6 +62,28 @@ int16_t lv_trigo_sin(int16_t angle);
|
|||||||
*/
|
*/
|
||||||
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3);
|
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a binary search within the given list.
|
||||||
|
*
|
||||||
|
* @note Code extracted out of https://github.com/torvalds/linux/blob/master/lib/bsearch.c
|
||||||
|
*
|
||||||
|
* @warning The contents of the array should already be in ascending sorted order
|
||||||
|
* under the provided comparison function.
|
||||||
|
*
|
||||||
|
* @note The key need not have the same type as the elements in
|
||||||
|
* the array, e.g. key could be a string and the comparison function
|
||||||
|
* could compare the string with the struct's name field. However, if
|
||||||
|
* the key and elements in the array are of the same type, you can use
|
||||||
|
* the same comparison function for both sort() and bsearch().
|
||||||
|
*
|
||||||
|
* @param key pointer to item being searched for
|
||||||
|
* @param base pointer to first element to search
|
||||||
|
* @param num number of elements
|
||||||
|
* @param size size of each element
|
||||||
|
* @param cmp pointer to comparison function (see #lv_font_codeCompare as a comparison function example)
|
||||||
|
*/
|
||||||
|
void * lv_bsearch(const void * key, const void * base, uint32_t num, uint32_t size, int32_t (* cmp)(const void * key, const void * elt));
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user