/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials
- provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*====================================================================*/
/*!
* \file heap.c
* <pre>
*
* Create/Destroy L_Heap
* L_HEAP *lheapCreate()
* void *lheapDestroy()
*
* Operations to add/remove to/from the heap
* l_int32 lheapAdd()
* static l_int32 lheapExtendArray()
* void *lheapRemove()
*
* Heap operations
* l_int32 lheapSwapUp()
* l_int32 lheapSwapDown()
* l_int32 lheapSort()
* l_int32 lheapSortStrictOrder()
*
* Accessors
* l_int32 lheapGetCount()
*
* Debug output
* l_int32 lheapPrint()
*
* The L_Heap is useful to implement a priority queue, that is sorted
* on a key in each element of the heap. The heap is an array
* of nearly arbitrary structs, with a l_float32 the first field.
* This field is the key on which the heap is sorted.
*
* Internally, we keep track of the heap size, n. The item at the
* root of the heap is at the head of the array. Items are removed
* from the head of the array and added to the end of the array.
* When an item is removed from the head, the item at the end
* of the array is moved to the head. When items are either
* added or removed, it is usually necessary to swap array items
* to restore the heap order. It is guaranteed that the number
* of swaps does not exceed log(n).
*
* -------------------------- N.B. ------------------------------
* The items on the heap (or, equivalently, in the array) are cast
* to void*. Their key is a l_float32, and it is REQUIRED that the
* key be the first field in the struct. That allows us to get the
* key by simply dereferencing the struct. Alternatively, we could
* choose (but don't) to pass an application-specific comparison
* function into the heap operation functions.
* -------------------------- N.B. ------------------------------
* </pre>
*/
#include <string.h>
#include "allheaders.h"
static const l_int32 MIN_BUFFER_SIZE = 20; /* n'importe quoi */
static const l_int32 INITIAL_BUFFER_ARRAYSIZE = 128; /* n'importe quoi */
#define SWAP_ITEMS(i, j) { void *tempitem = lh->array[(i)]; \
lh->array[(i)] = lh->array[(j)]; \
lh->array[(j)] = tempitem; }
/* Static function */
static l_int32 lheapExtendArray(L_HEAP *lh);
/*--------------------------------------------------------------------------*
* L_Heap create/destroy *
*--------------------------------------------------------------------------*/
/*!
* \brief lheapCreate()
*
* \param[in] nalloc size of ptr array to be alloc'd 0 for default
* \param[in] direction L_SORT_INCREASING, L_SORT_DECREASING
* \return lheap, or NULL on error
*/
L_HEAP *
lheapCreate(l_int32 nalloc,
l_int32 direction)
{
L_HEAP *lh;
PROCNAME("lheapCreate");
if (nalloc < MIN_BUFFER_SIZE)
nalloc = MIN_BUFFER_SIZE;
/* Allocate ptr array and initialize counters. */
if ((lh = (L_HEAP *)LEPT_CALLOC(1, sizeof(L_HEAP))) == NULL)
return (L_HEAP *)ERROR_PTR("lh not made", procName, NULL);
if ((lh->array = (void **)LEPT_CALLOC(nalloc, sizeof(void *))) == NULL) {
lheapDestroy(&lh, FALSE);
return (L_HEAP *)ERROR_PTR("ptr array not made", procName, NULL);
}
lh->nalloc = nalloc;
lh->n = 0;
lh->direction = direction;
return lh;
}
/*!
* \brief lheapDestroy()
*
* \param[in,out] plh to be nulled
* \param[in] freeflag TRUE to free each remaining struct in the array
* \return void
*
* <pre>
* Notes:
* (1) Use freeflag == TRUE when the items in the array can be
* simply destroyed using free. If those items require their
* own destroy function, they must be destroyed before
* calling this function, and then this function is called
* with freeflag == FALSE.
* (2) To destroy the lheap, we destroy the ptr array, then
* the lheap, and then null the contents of the input ptr.
* </pre>
*/
void
lheapDestroy(L_HEAP **plh,
l_int32 freeflag)
{
l_int32 i;
L_HEAP *lh;
PROCNAME("lheapDestroy");
if (plh == NULL) {
L_WARNING("ptr address is NULL\n", procName);
return;
}
if ((lh = *plh) == NULL)
return;
if (freeflag) { /* free each struct in the array */
for (i = 0; i < lh->n; i++)
LEPT_FREE(lh->array[i]);
} else if (lh->n > 0) { /* freeflag == FALSE but elements exist on array */
L_WARNING("memory leak of %d items in lheap!\n", procName, lh->n);
}
if (lh->array)
LEPT_FREE(lh->array);
LEPT_FREE(lh);
*plh = NULL;
return;
}
/*--------------------------------------------------------------------------*
* Accessors *
*--------------------------------------------------------------------------*/
/*!
* \brief lheapAdd()
*
* \param[in] lh heap
* \param[in] item to be added to the tail of the heap
* \return 0 if OK, 1 on error
*/
l_int32
lheapAdd(L_HEAP *lh,
void *item)
{
PROCNAME("lheapAdd");
if (!lh)
return ERROR_INT("lh not defined", procName, 1);
if (!item)
return ERROR_INT("item not defined", procName, 1);
/* If necessary, expand the allocated array by a factor of 2 */
if (lh->n >= lh->nalloc)
lheapExtendArray(lh);
/* Add the item */
lh->array[lh->n] = item;
lh->n++;
/* Restore the heap */
lheapSwapUp(lh, lh->n - 1);
return 0;
}
/*!
* \brief lheapExtendArray()
*
* \param[in] lh heap
* \return 0 if OK, 1 on error
*/
static l_int32
lheapExtendArray(L_HEAP *lh)
{
PROCNAME("lheapExtendArray");
if (!lh)
return ERROR_INT("lh not defined", procName, 1);
if ((lh->array = (void **)reallocNew((void **)&lh->array,
sizeof(void *) * lh->nalloc,
2 * sizeof(void *) * lh->nalloc)) == NULL)
return ERROR_INT("new ptr array not returned", procName, 1);
lh->nalloc = 2 * lh->nalloc;
return 0;
}
/*!
* \brief lheapRemove()
*
* \param[in] lh heap
* \return ptr to item popped from the root of the heap,
* or NUL
没有合适的资源?快使用搜索试试~ 我知道了~
tesseract-5.0.zip
共314个文件
h:286个
dll:18个
traineddata:2个
需积分: 31 51 下载量 42 浏览量
2019-10-24
14:54:27
上传
评论
收藏 50.26MB ZIP 举报
温馨提示
tesseract-5.0 vs2015 x86,资源包含:编译完成debug/release dll和lib, 依赖库,头文件
资源推荐
资源详情
资源评论
收起资源包目录
tesseract-5.0.zip (314个子文件)
heap.c 16KB
tesseract50d.dll 8.85MB
pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll 3.49MB
tesseract50.dll 2.68MB
pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll 1.87MB
pvt.cppan.demo.webp-0.6.1.dll 960KB
pvt.cppan.demo.tiff-4.0.9.dll 756KB
pvt.cppan.demo.openjpeg.openjp2-2.3.0.dll 669KB
pvt.cppan.demo.webp-0.6.1.dll 420KB
pvt.cppan.demo.jpeg-9.2.0.dll 401KB
pvt.cppan.demo.tiff-4.0.9.dll 382KB
pvt.cppan.demo.xz_utils.lzma-5.2.4.dll 332KB
pvt.cppan.demo.png-1.6.35.dll 305KB
pvt.cppan.demo.jpeg-9.2.0.dll 247KB
pvt.cppan.demo.openjpeg.openjp2-2.3.0.dll 233KB
pvt.cppan.demo.png-1.6.35.dll 157KB
pvt.cppan.demo.madler.zlib-1.2.11.dll 152KB
pvt.cppan.demo.xz_utils.lzma-5.2.4.dll 127KB
pvt.cppan.demo.madler.zlib-1.2.11.dll 73KB
tesseract.exe 106KB
tesseract.exe 37KB
allheaders.h 250KB
pix.h 60KB
tesseractclass.h 60KB
bmfdata.h 46KB
unicharset.h 43KB
colpartition.h 37KB
elst.h 36KB
baseapi.h 36KB
elst2.h 36KB
bbgrid.h 36KB
genericvector.h 36KB
pageres.h 33KB
clst.h 33KB
blobbox.h 31KB
dict.h 29KB
oclkernels.h 29KB
classify.h 28KB
tfnetwork.pb.h 27KB
capi.h 26KB
wordrec.h 25KB
ratngs.h 23KB
matrix.h 23KB
environ.h 23KB
recodebeam.h 22KB
dawg.h 22KB
lstmtrainer.h 21KB
points.h 21KB
language_model.h 20KB
trie.h 19KB
textord.h 19KB
colfind.h 17KB
strokewidth.h 17KB
rect.h 17KB
blobs.h 16KB
shapetable.h 16KB
tablefind.h 16KB
tabfind.h 16KB
tablerecog.h 16KB
networkio.h 15KB
recog.h 15KB
tabvector.h 15KB
pageiterator.h 15KB
scrollview.h 15KB
blamer.h 15KB
imagedata.h 15KB
normalis.h 14KB
network.h 14KB
makerow.h 13KB
mastertrainer.h 13KB
lstmrecognizer.h 13KB
paragraphs_internal.h 12KB
colpartitiongrid.h 12KB
publictypes.h 12KB
coutln.h 12KB
trainingsampleset.h 12KB
params.h 12KB
baselinedetect.h 11KB
readbarcode.h 11KB
dewarp.h 11KB
equationdetect.h 11KB
validator.h 11KB
arrayaccess.h 11KB
errorcounter.h 11KB
ltrresultiterator.h 11KB
imageio.h 11KB
textlineprojection.h 10KB
unicharcompress.h 10KB
renderer.h 10KB
resultiterator.h 10KB
lm_state.h 10KB
tessdatamanager.h 10KB
networkscratch.h 10KB
morph.h 9KB
pango_font_info.h 9KB
genericheap.h 9KB
rejctmap.h 9KB
ambigs.h 9KB
topitch.h 9KB
intproto.h 9KB
共 314 条
- 1
- 2
- 3
- 4
资源评论
li1234lin_139com
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Java知识体系最强总结(2021版).txt
- Python知识点Python知识点Python知识点Python知识点Python知识点PythonPython知识点.txt
- Java开发基于seetaface6的人脸识别(活体检测)的封装源码.zip
- JSP在线失物招领管理平台源码.zip
- JSP在线旅游美食展现管理系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功