📄 yc_algorithm.h
字号:
/*
* The young Library
* Copyright (c) 2006 by Yang Huan(杨桓)
* Permission to use, copy, modify, distribute and sell this software for any
* purpose is hereby granted without fee, provided that the above copyright
* notice appear in all copies and that both that copyright notice and this
* permission notice appear in supporting documentation.
* The author make no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*/
/******************************************************************************/
/******************************************************************************/
#ifndef __MACRO_C_YOUNG_LIBRARY_ALGORITHM_HEADER_FILE__
#define __MACRO_C_YOUNG_LIBRARY_ALGORITHM_HEADER_FILE__
/******************************************************************************/
#include "yc_definition.h"
#include "yc_memalgo.h"
#include "yc_rscalgo.h"
#ifdef __cplusplus
namespace youngc { extern "C" {
#endif
/******************************************************************************/
/******************************************************************************/
typedef struct
{
const void* first;
const void* second;
} pair_pointer;
/******************************************************************************/
/* 对 [first, first + count) 排序 */
void quicksort( void* first,
size_t count,
size_t element_size,
ylib_fp_cmp_t compare,
void (*swap)( void* element1, void* element2 ) );
/* 寻找在 [first, first + count) 中第一个与 value 相等的元素 */
const void* find( const void* first,
size_t count,
size_t element_size,
const void* value,
ylib_fp_cmp_t compare );
/* 寻找在 [master_first, master_first + master_count)
* 中和 [sub_first, sub_first + sub_count) 匹配的子区间*/
const void* search( const void* master_first,
size_t master_count,
const void* sub_first,
size_t sub_count,
size_t element_size,
ylib_fp_cmp_t compare );
/* 比较 [first1, first1 + count1) 和 [first2, first2 + count2) 是否完全匹配 */
bool matching( const void* first1,
size_t count1,
const void* first2,
size_t count2,
size_t element_size,
ylib_fp_cmp_t compare );
/* 在 [first, first + count) 内插入 value 时的上界位置 */
const void* lower_bound( const void* first,
size_t count,
size_t element_size,
const void* value,
ylib_fp_cmp_t compare );
/* 在 [first, first + count) 内插入 value 时的下界位置 */
const void* upper_bound( const void* first,
size_t count,
size_t element_size,
const void* value,
ylib_fp_cmp_t compare );
/* 在 [first, first + count) 内寻找等于 value 的元素的有效区间 */
pair_pointer equal_range( const void* first,
size_t count,
size_t element_size,
const void* value,
ylib_fp_cmp_t compare );
/* 在 [first, first + count) 内统计等于 value 的元素的个数 */
size_t count( const void* first,
size_t count,
size_t element_size,
const void* value,
ylib_fp_cmp_t compare );
/* 求 [first, first + count) 内最小元素所在的位置 */
const void* min_element( const void* first,
size_t count,
size_t element_size,
ylib_fp_cmp_t compare );
/* 求 [first, first + count) 内最大元素所在的位置 */
const void* max_element( const void* first,
size_t count,
size_t element_size,
ylib_fp_cmp_t compare );
/******************************************************************************/
/******************************************************************************/
#ifdef __cplusplus
} }
#endif
#endif
/******************************************************************************/
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -