# class BDB::Btree

### Public Instance Methods

compact(p1 = v1, p2 = v2, p3 = v3) click to toggle source

    static VALUE
    bdb_treerec_compact(int argc, VALUE *argv, VALUE obj)
    {
        bdb_DB *dbst;
        DB_TXN *txnid;
        DBT start, stop, end;
        DBT *pstart, *pstop;
        DB_COMPACT cdata;
        db_recno_t recno_start, recno_stop;
        int flags;
        VALUE a, b, c, result;

        pstop = pstart = NULL;
        MEMZERO(&cdata, DB_COMPACT, 1);
        flags = 0;
        INIT_TXN(txnid, obj, dbst);
        switch (rb_scan_args(argc, argv, "03", &a, &b, &c)) {
        case 3:
            if (FIXNUM_P(c)) {
                flags = NUM2INT(c);
            }
            else {
                struct data_flags *dtf;
                VALUE dtobj;

                dtobj = Data_Make_Struct(rb_cData, struct data_flags, 0, free, dtf);
                dtf->cdata = &cdata;
                dtf->flags = 0;
                rb_iterate(rb_each, c, bdb_compact_i, dtobj);
                flags = dtf->flags;
            }
            /* ... */
        case 2:
            if (!NIL_P(b)) {
                MEMZERO(&stop, DBT, 1);
                b = bdb_test_recno(obj, &start, &recno_stop, b);
                pstop = &stop;
            }
            /* ... */
        case 1:
            if (!NIL_P(a)) {
                MEMZERO(&start, DBT, 1);
                a = bdb_test_recno(obj, &start, &recno_start, a);
                pstart = &start;
            }
        }
        MEMZERO(&end, DBT, 1);
        bdb_test_error(dbst->dbp->compact(dbst->dbp, txnid, pstart, pstop, &cdata,
                                          flags, &end));
        result = rb_hash_new();
        rb_hash_aset(result, rb_tainted_str_new2("end"), bdb_test_load_key(obj, &end));
        rb_hash_aset(result, rb_tainted_str_new2("compact_deadlock"),
                     INT2NUM(cdata.compact_deadlock));
        rb_hash_aset(result, rb_tainted_str_new2("compact_levels"),
                     INT2NUM(cdata.compact_levels));
        rb_hash_aset(result, rb_tainted_str_new2("compact_pages_free"),
                     INT2NUM(cdata.compact_pages_free));
        rb_hash_aset(result, rb_tainted_str_new2("compact_pages_examine"),
                     INT2NUM(cdata.compact_pages_examine));
        rb_hash_aset(result, rb_tainted_str_new2("compact_pages_truncated"),
                     INT2NUM(cdata.compact_pages_truncated));
        return result;
    }

each_by_prefix(*args) click to toggle source

    static VALUE
    bdb_each_prefix(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_each_kvc(argc, argv, obj, DB_NEXT, Qfalse, BDB_ST_KV | BDB_ST_PREFIX);
    }

key_range(p1) click to toggle source

    static VALUE
    bdb_btree_key_range(obj, a)
        VALUE obj, a;
    {
        bdb_DB *dbst;
        DB_TXN *txnid;
        DBT key;
        db_recno_t recno;
        DB_KEY_RANGE key_range;
        volatile VALUE b = Qnil;

        INIT_TXN(txnid, obj, dbst);
        MEMZERO(&key, DBT, 1);
        b = bdb_test_recno(obj, &key, &recno, a);
        bdb_test_error(dbst->dbp->key_range(dbst->dbp, txnid, &key, &key_range, 0));
        return rb_struct_new(bdb_sKeyrange,
                             rb_float_new(key_range.less),
                             rb_float_new(key_range.equal),
                             rb_float_new(key_range.greater));
    }

reverse_each_by_prefix(*args) click to toggle source

    static VALUE
    bdb_each_xiferp(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_each_kvc(argc, argv, obj, DB_PREV, Qfalse,
                            BDB_ST_KV | BDB_ST_ONE | BDB_ST_PREFIX);
    }

stat(p1 = v1) click to toggle source

    endif

    VALUE
    bdb_tree_stat(int argc, VALUE *argv, VALUE obj)
    {
        bdb_DB *dbst;
        DB_BTREE_STAT *bdb_stat;
        VALUE hash, flagv;
        char pad;
        int flags = 0;
    #if HAVE_DB_STAT_4_TXN
        DB_TXN *txnid = NULL;
    #endif

        if (rb_scan_args(argc, argv, "01", &flagv) == 1) {
            flags = NUM2INT(flagv);
        }
        GetDB(obj, dbst);
    #if HAVE_DB_STAT_4
    #if HAVE_DB_STAT_4_TXN
        if (RTEST(dbst->txn)) {
            bdb_TXN *txnst;

            GetTxnDB(dbst->txn, txnst);
            txnid = txnst->txnid;
        }
        bdb_test_error(dbst->dbp->stat(dbst->dbp, txnid, &bdb_stat, flags));
    #else
        bdb_test_error(dbst->dbp->stat(dbst->dbp, &bdb_stat, 0, flags));
    #endif
    #else
        bdb_test_error(dbst->dbp->stat(dbst->dbp, &bdb_stat, flags));
    #endif
        hash = rb_hash_new();
        rb_hash_aset(hash, rb_tainted_str_new2("bt_magic"), INT2NUM(bdb_stat->bt_magic));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_version"), INT2NUM(bdb_stat->bt_version));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_dup_pg"), INT2NUM(bdb_stat->bt_dup_pg));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_dup_pgfree"), INT2NUM(bdb_stat->bt_dup_pgfree));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_free"), INT2NUM(bdb_stat->bt_free));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_int_pg"), INT2NUM(bdb_stat->bt_int_pg));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_int_pgfree"), INT2NUM(bdb_stat->bt_int_pgfree));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_leaf_pg"), INT2NUM(bdb_stat->bt_leaf_pg));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_leaf_pgfree"), INT2NUM(bdb_stat->bt_leaf_pgfree));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_levels"), INT2NUM(bdb_stat->bt_levels));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_minkey"), INT2NUM(bdb_stat->bt_minkey));
    #if HAVE_ST_DB_BTREE_STAT_BT_NRECS
        rb_hash_aset(hash, rb_tainted_str_new2("bt_nrecs"), INT2NUM(bdb_stat->bt_nrecs));
    #endif
    #if HAVE_ST_DB_BTREE_STAT_BT_NKEYS
        rb_hash_aset(hash, rb_tainted_str_new2("bt_nkeys"), INT2NUM(bdb_stat->bt_nkeys));
    #if ! HAVE_ST_DB_BTREE_STAT_BT_NRECS
        rb_hash_aset(hash, rb_tainted_str_new2("bt_nrecs"), INT2NUM(bdb_stat->bt_nkeys));
    #endif
    #endif
    #if HAVE_ST_DB_BTREE_STAT_BT_NDATA
        rb_hash_aset(hash, rb_tainted_str_new2("bt_ndata"), INT2NUM(bdb_stat->bt_ndata));
    #endif
        rb_hash_aset(hash, rb_tainted_str_new2("bt_over_pg"), INT2NUM(bdb_stat->bt_over_pg));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_over_pgfree"), INT2NUM(bdb_stat->bt_over_pgfree));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_pagesize"), INT2NUM(bdb_stat->bt_pagesize));
        rb_hash_aset(hash, rb_tainted_str_new2("bt_re_len"), INT2NUM(bdb_stat->bt_re_len));
        pad = (char)bdb_stat->bt_re_pad;
        rb_hash_aset(hash, rb_tainted_str_new2("bt_re_pad"), rb_tainted_str_new(&pad, 1));
    #if HAVE_ST_DB_BTREE_STAT_BT_PAGECNT
        rb_hash_aset(hash, rb_tainted_str_new2("bt_pagecnt"), INT2NUM(bdb_stat->bt_pagecnt));
    #endif
        free(bdb_stat);
        return hash;
    }