当前位置: 首页>>代码示例>>C++>>正文


C++ DB::set_bt_compare方法代码示例

本文整理汇总了C++中DB::set_bt_compare方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::set_bt_compare方法的具体用法?C++ DB::set_bt_compare怎么用?C++ DB::set_bt_compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::set_bt_compare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
bdb_open(void)
{
	DB *db;
	DBC *dbc;
	DB_ENV *dbenv;

	assert(db_env_create(&dbenv, 0) == 0);
	dbenv->set_errpfx(dbenv, "bdb");
	dbenv->set_errfile(dbenv, stderr);
	assert(dbenv->mutex_set_max(dbenv, 10000) == 0);
	assert(dbenv->set_cachesize(dbenv, 0, 50 * 1024 * 1024, 1) == 0);
	assert(dbenv->open(dbenv, NULL,
	    DB_CREATE |
	    (g.c_delete_pct == 0 && g.c_insert_pct == 0 && g.c_write_pct == 0 ?
	    0 : DB_INIT_LOCK) |
	    DB_INIT_MPOOL | DB_PRIVATE, 0) == 0);
	assert(db_create(&db, dbenv, 0) == 0);

	if (g.c_file_type == ROW && g.c_reverse)
		assert(db->set_bt_compare(db, bdb_compare_reverse) == 0);

	assert(db->open(db, NULL, "__bdb", NULL, DB_BTREE, DB_CREATE, 0) == 0);
	g.bdb = db;
	assert(db->cursor(db, NULL, &dbc, 0) == 0);
	g.dbc = dbc;

	key_gen_setup(&keybuf);
}
开发者ID:qixin,项目名称:wiredtiger,代码行数:29,代码来源:bdb.c

示例2: int

DB *sg_open_db(DB_ENV *dbenv, char *filename,
	       int (*bt_compare_fcn)(DB *, const DBT *, const DBT *) )
{
    int ret;
    DB *dbp = NULL;

    if ((ret = db_create(&dbp, dbenv , 0)) != 0) {
	ci_debug_printf(1, "db_create: %s\n", db_strerror(ret));
	return NULL;
    }
    //     dbp->set_flags(dbp, DB_DUP);
    dbp->set_bt_compare(dbp, bt_compare_fcn);


#if(DB_VERSION_MINOR>=1)
    if ((ret = dbp->open( dbp, NULL, filename, NULL,
			  DB_BTREE, DB_RDONLY|DB_THREAD, 0)) != 0)
#else
	if ((ret = dbp->open( dbp, filename, NULL,
			      DB_BTREE, DB_RDONLY, 0)) != 0)
#endif
	{
	    ci_debug_printf(1, "open db %s: %s\n", filename, db_strerror(ret));
	    dbp->close(dbp, 0);
	    return NULL;
	}
    return dbp;
}
开发者ID:p1rate5s,项目名称:c-icap,代码行数:28,代码来源:sguardDB.c

示例3: pctlmfdb_open

int pctlmfdb_open(struct pctldb_st *pctldb,
		  struct pctldb_param_st *param, int *dberror){

  DB *mfdbp = NULL;
  int status;
  uint32_t dbflags = PCTLMFDB_FLAGS;

  status = db_create(&mfdbp, param->dbenv, 0);

  if(status == 0)
    status = mfdbp->set_bt_compare(mfdbp, timespec_cmp);

  if(status == 0)
    status = mfdbp->open(mfdbp, NULL, param->mfdbname, NULL, DB_BTREE, dbflags,
			 param->mode);

  if(status != 0){
    if(mfdbp != NULL)
      mfdbp->close(mfdbp, 0);

    *dberror = status;
    status = -1;
  }

  if(status == 0)
    pctldb->mfdbp = mfdbp;

  return(status);
}
开发者ID:Adnan-Polewall,项目名称:nbsp,代码行数:29,代码来源:pctlmfdb.c

示例4: abort

DB *icalbdbset_bdb_open(const char *path, const char *subdb, int dbtype, int mode, u_int32_t flag)
{
    DB *dbp = NULL;
    int ret;
    u_int32_t flags;

    /* Initialize the correct set of db subsystems (see capdb.c) */
    flags = (u_int32_t) (DB_CREATE | DB_THREAD);

    /* should just abort here instead of opening an env in the current dir..  */
    if (!ICAL_DB_ENV) {
        if (icalbdbset_init_dbenv(NULL, NULL) != 0) {
            return NULL;
        }
    }

    /* Create and initialize database object, open the database. */
    if ((ret = db_create(&dbp, ICAL_DB_ENV, 0)) != 0) {
        return NULL;
    }

    /* set comparison function, if BTREE */
    if (dbtype == DB_BTREE) {
        dbp->set_bt_compare(dbp, _compare_keys);
    }

    /* set DUP, DUPSORT */
    if (flag != 0) {
        dbp->set_flags(dbp, flag);
    }

    if ((ret = dbp->open(dbp, NULL, path, subdb, dbtype, flags, mode)) != 0) {
        ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "%s (database: %s): open failed.", path, subdb);
        if (ret == DB_RUNRECOVERY) {
            abort();
        } else {
            return NULL;
        }
    }

    return dbp;
}
开发者ID:BenjamenMeyer,项目名称:libical,代码行数:42,代码来源:icalbdbset.c

示例5: return

/*
 * csv_secondary_open --
 *	Open any secondary indices.
 */
int
csv_secondary_open()
{
    DB *sdb;
    DbField *f;
    int ret, (*fcmp)(DB *, const DBT *, const DBT *);

    /*
     * Create secondary database handles.
     */
    for (f = fieldlist; f->name != NULL; ++f) {
        if (f->indx == 0)
            continue;

        if ((ret = db_create(&sdb, dbenv, 0)) != 0) {
            dbenv->err(dbenv, ret, "db_create");
            return (1);
        }
        sdb->app_private = f;

        /* Keys are small, use a relatively small page size. */
        if ((ret = sdb->set_pagesize(sdb, 8 * 1024)) != 0) {
            dbenv->err(dbenv, ret, "DB->set_pagesize");
            return (1);
        }

        /*
         * Sort the database based on the underlying type.  Skip
         * strings, Berkeley DB defaults to lexicographic sort.
         */
        switch (f->type) {
        case DOUBLE:
            fcmp = compare_double;
            break;
        case ULONG:
            fcmp = compare_ulong;
            break;
        case NOTSET:
        case STRING:
        default:
            fcmp = NULL;
            break;
        }
        if (fcmp != NULL &&
                (ret = sdb->set_bt_compare(sdb, fcmp)) != 0) {
            dbenv->err(dbenv, ret, "DB->set_bt_compare");
            return (1);
        }

        /* Always configure secondaries for sorted duplicates. */
        if ((ret = sdb->set_flags(sdb, DB_DUPSORT)) != 0) {
            dbenv->err(dbenv, ret, "DB->set_flags");
            return (1);
        }
        if ((ret = sdb->set_dup_compare(sdb, compare_ulong)) != 0) {
            dbenv->err(dbenv, ret, "DB->set_dup_compare");
            return (1);
        }

        if ((ret = sdb->open(
                       sdb, NULL, f->name, NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
            dbenv->err(dbenv, ret, "DB->open: %s", f->name);
            return (1);
        }
        if ((ret = sdb->associate(
                       db, NULL, sdb, secondary_callback, DB_CREATE)) != 0) {
            dbenv->err(dbenv, ret, "DB->set_associate");
            return (1);
        }
        f->secondary = sdb;
    }

    return (0);
}
开发者ID:vogth,项目名称:chandler,代码行数:78,代码来源:db.c

示例6: return

/*
 *  worker function shared between top10Users and top10Groups
 *
 *  Creates in-memory only database to store temporary results
 *  as long as done == FALSE.  As soon as done is set to TRUE,
 *  generate the top10 lists for the database.
 *
 *  The results parameter is used to pass the database pointer around
 *  while calculating, then changes to an agg_type_t when complete.
 *
 */
static int
do_top10(filinfo_t *filinfo, filvar_t *filvar, boolean_t done,	/* ARGSUSED */
         fm_rptno_t which, fmFuncRes_t *results)
{
    int		st;
    DB		*dbp;
    DBC		*curs;
    DBT		key;
    DBT		data;
    DB_TXN		*txn = NULL;
    agg_size_t	agg;
    agg_list_t	*agglist = NULL;
    agg_size_t	*aggp;
    int		i;
    agg_size_t	*aggreport;

    dbp = results->rptDB;

    if (done == FALSE) {
        if ((filinfo == NULL) || (filvar == NULL)) {
            return (-1);
        }

        if (dbp == NULL) {
            st = db_create(&dbp, dbEnv, 0);
            if (st != 0) {
                return (st);
            }
            /* no duplicates, sort on id */
            st = dbp->set_bt_compare(dbp, bt_compare_uint64);
            if (st != 0) {
                dbp->remove(dbp, NULL, NULL, 0);
                return (st);
            }

            st = dbp->open(dbp, NULL, NULL, NULL, DB_BTREE,
                           db_fl, 0644);
            if (st != 0) {
                dbp->remove(dbp, NULL, NULL, 0);
                return (st);
            }

            results->rptDB = dbp;
        }

        memset(&agg, 0, sizeof (agg_size_t));

        if (which == TOP_USERS) {
            agg.id = filinfo->owner;
        } else {
            agg.id = filinfo->group;
        }

        /* fetch id info if it exists */
        memset(&key, 0, sizeof (DBT));
        memset(&data, 0, sizeof (DBT));

        key.data = &agg.id;
        key.size = sizeof (uint64_t);

        data.data = &agg;
        data.size = data.ulen = sizeof (agg_size_t);
        data.flags = DB_DBT_USERMEM;

        dbEnv->txn_begin(dbEnv, NULL, &txn, 0);
        st = dbp->get(dbp, txn, &key, &data, 0);

        if ((st != 0) && (st != DB_NOTFOUND)) {
            txn->abort(txn);
            return (st);
        }

        agg.count++;
        agg.total_size += filinfo->size;
        agg.total_osize += filinfo->osize;

        st = dbp->put(dbp, txn, &key, &data, 0);
        if (st == 0) {
            st = txn->commit(txn, 0);
        } else {
            txn->abort(txn);
        }
    }

    /* final processing */
    if (done == TRUE) {
        uint64_t	aggid = 0;
        int 		numids = 0;
        agg_list_t	*aggent;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samqfs,代码行数:101,代码来源:file_metrics.c

示例7: rpmGenPath


//.........这里部分代码省略.........
			rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
			rc = cvtdberr(dbi, "db->set_h_nelem", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_flags) {
			rc = db->set_flags(db, dbi->dbi_h_flags);
			rc = cvtdberr(dbi, "db->set_h_flags", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_hash_fcn) {
			rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
			rc = cvtdberr(dbi, "db->set_h_hash", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_dup_compare_fcn) {
			rc = db->set_dup_compare(db, dbi->dbi_h_dup_compare_fcn);
			rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug);
			if (rc) break;
		    }
		    break;
		case DB_BTREE:
/* 4.1: db->set_append_recno(???) */
		    if (dbi->dbi_bt_flags) {
			rc = db->set_flags(db, dbi->dbi_bt_flags);
			rc = cvtdberr(dbi, "db->set_bt_flags", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_minkey) {
			rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
			rc = cvtdberr(dbi, "db->set_bt_minkey", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_compare_fcn) {
			rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
			rc = cvtdberr(dbi, "db->set_bt_compare", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_dup_compare_fcn) {
			rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
			rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_prefix_fcn) {
			rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
			rc = cvtdberr(dbi, "db->set_bt_prefix", rc, _debug);
			if (rc) break;
		    }
		    break;
		case DB_RECNO:
		    if (dbi->dbi_re_delim) {
/* 4.1: db->set_append_recno(???) */
			rc = db->set_re_delim(db, dbi->dbi_re_delim);
			rc = cvtdberr(dbi, "db->set_re_selim", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_len) {
			rc = db->set_re_len(db, dbi->dbi_re_len);
			rc = cvtdberr(dbi, "db->set_re_len", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_pad) {
			rc = db->set_re_pad(db, dbi->dbi_re_pad);
			rc = cvtdberr(dbi, "db->set_re_pad", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_source) {
开发者ID:xrg,项目名称:RPM,代码行数:67,代码来源:db3.c

示例8: sizeof

int
open_fs_db(
	char		*dirnam,
	char		*fsname,
	DB_ENV		*p_env,
	boolean_t	create,		/* add new databases if not existing */
	fs_db_t		*fsdb)
{
	DB		*pdb;
	int		st;
	char		buf[MAXPATHLEN+1];
	mode_t		md = 0644;
	char		namebuf[MAXPATHLEN+1] = {0};
	struct stat64	sbuf;

	memset(fsdb, 0, sizeof (fs_db_t));

	/* make sure fs-specific directory exists */
	st = dbdir_from_fsname(fsname, namebuf, sizeof (namebuf));
	if (st != 0) {
		goto err;
	}

	snprintf(buf, sizeof (buf), "%s/%s", dirnam, namebuf);

	if (!create) {
		if (stat64(buf, &sbuf) != 0) {
			return (ENOENT);
		}
	}
	(void) mkdirp(buf, 0744);

	if (fsdb->snapDB == NULL) {
		/* Create & open the snapshot database - RECNO */
		snprintf(buf, sizeof (buf), "%s/snaps.db", namebuf);

		if ((st = db_create(&fsdb->snapDB, p_env, 0)) != 0) {
			goto err;
		}

		pdb = fsdb->snapDB;

		if ((st = pdb->set_append_recno(pdb, set_snapid)) != 0) {
			goto err;
		}

		if ((st = pdb->open(pdb, NULL, buf, NULL, DB_RECNO,
		    db_fl, md)) != 0) {
			goto err;
		}

		/*  create the secondary for the snapdb */
		snprintf(buf, sizeof (buf), "%s/snapid.db", namebuf);

		if ((st = db_create(&fsdb->snapidDB, p_env, 0)) != 0) {
			goto err;
		}

		pdb = fsdb->snapidDB;

		pdb->set_bt_compare(pdb, compare_pathname);

		if ((st = pdb->open(pdb, NULL, buf, NULL, DB_BTREE, db_fl,
		    md)) != 0) {
			goto err;
		}

		if ((st = (fsdb->snapDB)->associate(fsdb->snapDB, NULL, pdb,
		    index_snapname, DB_CREATE)) != 0) {
			goto err;
		}
	}

	if (fsdb->fidDB == NULL) {
		/* Path components by FID - Primary, BTREE */
		snprintf(buf, sizeof (buf), "%s/path_fid.db", namebuf);

		if ((st = db_create(&fsdb->fidDB, p_env, 0)) != 0) {
			goto err;
		}

		pdb = fsdb->fidDB;

		pdb->set_bt_compare(pdb, bt_compare_uint64);

		if ((st = pdb->open(pdb, NULL, buf, NULL, DB_BTREE, db_fl,
		    md)) != 0) {
			goto err;
		}

		/* pathname DB - BTREE */
		snprintf(buf, sizeof (buf), "%s/path.db", namebuf);

		if ((st = db_create(&fsdb->pathDB, p_env, 0)) != 0) {
			goto err;
		}

		pdb = fsdb->pathDB;

		pdb->set_bt_compare(pdb, compare_path_t);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samqfs,代码行数:101,代码来源:mkdb.c

示例9: if

static int 
dbverify_ext( ldbm_instance *inst, int verbose )
{
    char dbdir[MAXPATHLEN];
    char *filep           = NULL;
    PRDir *dirhandle      = NULL;
    PRDirEntry *direntry  = NULL;
    DB *dbp               = NULL;
    size_t tmplen            = 0;
    size_t filelen           = 0;
    int rval              = 1;
    int rval_main         = 0;
    struct ldbminfo *li   = inst->inst_li;
    dblayer_private *priv = (dblayer_private*)li->li_dblayer_private;
    struct dblayer_private_env *pEnv = priv->dblayer_env;

    dbdir[sizeof(dbdir)-1] = '\0';
    PR_snprintf(dbdir, sizeof(dbdir), "%s/%s", inst->inst_parent_dir_name,
                                               inst->inst_dir_name);
    if ('\0' != dbdir[sizeof(dbdir)-1]) /* overflown */
    {
        slapi_log_err(SLAPI_LOG_ERR, "dbverify_ext",
                        "db path too long: %s/%s\n",
                         inst->inst_parent_dir_name, inst->inst_dir_name);
        return 1;
    }
    tmplen = strlen(dbdir);
    filep = dbdir + tmplen;
    filelen = sizeof(dbdir) - tmplen;

    /* run dbverify on each each db file */
    dirhandle = PR_OpenDir(dbdir);
    if (! dirhandle)
    {
        slapi_log_err(SLAPI_LOG_ERR, "dbverify_ext",
                        "PR_OpenDir (%s) failed (%d): %s\n", 
                        dbdir, PR_GetError(),slapd_pr_strerror(PR_GetError()));
        return 1;
    }
    while (NULL !=
          (direntry = PR_ReadDir(dirhandle, PR_SKIP_DOT | PR_SKIP_DOT_DOT)))
    {
        /* struct attrinfo *ai = NULL; */
        dbp = NULL;

        if (!direntry->name)
        {
            break;
        }
        if (!strstr(direntry->name, LDBM_FILENAME_SUFFIX)) /* non db file */
        {
            continue;
        }
        if (sizeof(direntry->name) + 2 > filelen)
        {
            slapi_log_err(SLAPI_LOG_ERR, "dbverify_ext",
                                        "db path too long: %s/%s\n",
                                         dbdir, direntry->name);
            continue;
        }
        PR_snprintf(filep, filelen, "/%s", direntry->name);
        rval = db_create(&dbp, pEnv->dblayer_DB_ENV, 0);
        if (0 != rval)
        {
            slapi_log_err(SLAPI_LOG_ERR, "dbverify_ext",
                        "Unable to create id2entry db file %d\n", rval);
            return rval;
        }

#define VLVPREFIX "vlv#"
        if (0 != strncmp(direntry->name, ID2ENTRY, strlen(ID2ENTRY)))
        {
            struct attrinfo *ai = NULL;
            char *p = NULL;
            p = strstr(filep, LDBM_FILENAME_SUFFIX); /* since already checked,
                                                        it must have it */
            if(p)
                *p = '\0';
            ainfo_get( inst->inst_be, filep+1, &ai );
            if(p)
                *p = '.';
            if (ai->ai_key_cmp_fn) {
                dbp->app_private = (void *)ai->ai_key_cmp_fn;
                dbp->set_bt_compare(dbp, dblayer_bt_compare);
            }
            if (idl_get_idl_new())
            {
                rval = dbp->set_pagesize(dbp,
                        (priv->dblayer_index_page_size == 0) ?
                        DBLAYER_INDEX_PAGESIZE : priv->dblayer_index_page_size);
            }
            else
            {
                rval = dbp->set_pagesize(dbp,
                        (priv->dblayer_page_size == 0) ?
                        DBLAYER_PAGESIZE : priv->dblayer_page_size);
            }
            if (0 != rval)
            {
                slapi_log_err(SLAPI_LOG_ERR, "DB verify",
//.........这里部分代码省略.........
开发者ID:Firstyear,项目名称:ds,代码行数:101,代码来源:dbverify.c

示例10: main

int main(int argc, const char *argv[])
{
	DB *dbp;
	int error;
	const char *progname = argv[0];
	const char *dbname = argv[1];
	int retval = 0;
	struct dbfs_fsinfo_data dfd;
	struct dbfs_dentry_key *ddk;
	struct dbfs_dentry_data ddd;
	size_t ddk_size;

	if (argc != 2) {
		fprintf(stderr, "Format: %s file name\n", progname);
		goto out1;
	}
	if ((error = db_create(&dbp, NULL, 0))) {
		fprintf(stderr, "%s: db_create failed", progname);	
		goto out1;
	}
	dbp->set_errfile(dbp, stderr);
	dbp->set_errpfx(dbp, progname);

	if ((error = dbp->set_bt_compare(dbp, dbfs_bt_compare))) {
		dbp->err(dbp, error, "%s: open failed", dbname);
		goto out1;
	}

	/* Create database */
	if ((error = dbp->open(dbp,
	    NULL, dbname, NULL, DB_BTREE, DB_CREATE | DB_EXCL | DB_THREAD, 0664))) {
		dbp->err(dbp, error, "open: %s", dbname);
		goto out1;
	}

	ddk_size = dbfs_ddk_size("/");
	if (!(ddk = malloc(ddk_size))) {
		goto out2;
	}

	dbfs_init_dentry_key("/", ddk);

	if ((error = dbfs_create_attr(dbp, ddk, ddk_size, &ddd, mangoo_container, 
		S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, DBFS_ROOT_INO))) {
		goto out2;
	}

	dfd.dfd_lastino = DBFS_ROOT_INO;

	if ((error = dbfs_create_fsinfo(dbp, &dfd)))
		goto out2;

	printf("dbfs created successfully.\n");

out2:
	if ((dbp->close(dbp, 0))) {
		fprintf(stderr, "%s: close failed", progname);	
	}

out1:
	return retval;
}
开发者ID:AdityaRandive,项目名称:Project_Mangoo,代码行数:62,代码来源:mkdbfs.c


注:本文中的DB::set_bt_compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。