⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btsearch.cpp

📁 CBASE v1.01 采用Borland公司TC++编写的数据库管理源程序库
💻 CPP
字号:
/*	Copyright (c) 1989 Citadel	*/
/*	   All Rights Reserved    	*/

/* #ident	"@(#)btsearch.c	1.4 - 90/06/20" */

#include <blkio.h>
#include <errno.h>

/* local headers */
#include "btree_.h"

/*man---------------------------------------------------------------------------
NAME
     btsearch - search a btree

SYNOPSIS
     #include <btree.h>

     int btsearch(btp, buf)
     btree_t *btp;
     const void *buf;

DESCRIPTION
     The btsearch function searches the btree btp for the key pointed
     to by buf.  If it is found, the cursor is set to the location of
     the key and 1 is returned.  If it is not found, the cursor is set
     to the next higher key and 0 is returned.

     btsearch will fail if one or more of the following is true:

     [EINVAL]       btp is not a valid btree pointer.
     [EINVAL]       buf is the NULL pointer.
     [BTELOCK]      btp is not read locked.

SEE ALSO
     btdelcur, btdelete, btinsert.

DIAGNOSTICS
     Upon successful completion, a value of 1 is returned if the key
     was found or a value of 0 if it was not found.  On failure, a
     value of -1 is returned, and errno set to indicate the error.
     
------------------------------------------------------------------------------*/
int btsearch(btree_t *btp, const void *buf)
{
	int found = 0;		/* key found flag */

	/* validate arguments */
	if (!bt_valid(btp) || buf == NULL) {
		errno = EINVAL;
		return -1;
	}

	/* check locks */
	if (!(btp->flags & BTRDLCK)) {
		errno = BTELOCK;
		return -1;
	}

	/* search to position to insert */
	found = bt_search(btp, buf);
	if (found == -1) {
		BTEPRINT;
		return -1;
	}

	/* check if cursor on empty slot */
	if (found == 0) {
		if (btp->cbtpos.key > btp->cbtnp->n) {
			btp->cbtpos.key = btp->cbtnp->n;
			if (btnext(btp) == -1) {
				BTEPRINT;
				return -1;
			}
		}
	}

	errno = 0;
	return ((found == 1) ? 1: 0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -