# class BDB::Queue

### Public Class Methods

create(*args) click to toggle source

    static VALUE
    bdb_queue_s_new(int argc, VALUE *argv, VALUE obj)
    {
        VALUE *nargv, ret, restobj;
        struct re *rest;
        bdb_DB *dbst;

        restobj = Data_Make_Struct(obj, struct re, 0, free, rest);
        rest->re_len = -1;
        rest->re_pad = -1;
        if (argc && TYPE(argv[argc - 1]) == T_HASH) {
            rb_iterate(rb_each, argv[argc - 1], bdb_queue_i_search_re_len, restobj);
            if (rest->re_len <= 0) {
                rest->re_len = DEFAULT_RECORD_LENGTH;
                rb_hash_aset(argv[argc - 1], rb_tainted_str_new2("set_re_len"), INT2NUM(rest->re_len));
            }
            if (rest->re_pad < 0) {
                rest->re_pad = DEFAULT_RECORD_PAD;
                rb_hash_aset(argv[argc - 1], rb_tainted_str_new2("set_re_pad"), INT2NUM(rest->re_pad));
            }
            nargv = argv;
        }
        else {
            nargv = ALLOCA_N(VALUE, argc + 1);
            MEMCPY(nargv, argv, VALUE, argc);
            nargv[argc] = rb_hash_new();
            rest->re_len = DEFAULT_RECORD_LENGTH;
            rest->re_pad = DEFAULT_RECORD_PAD;
            rb_hash_aset(nargv[argc], rb_tainted_str_new2("set_re_len"), INT2NUM(DEFAULT_RECORD_LENGTH));
            rb_hash_aset(nargv[argc], rb_tainted_str_new2("set_re_pad"), INT2NUM(DEFAULT_RECORD_PAD));
            argc += 1;
        }
        ret = bdb_s_new(argc, nargv, obj);
        Data_Get_Struct(ret, bdb_DB, dbst);
        dbst->re_len = rest->re_len;
        dbst->re_pad = rest->re_pad;
        return ret;
    }

new(*args) click to toggle source

    static VALUE
    bdb_queue_s_new(int argc, VALUE *argv, VALUE obj)
    {
        VALUE *nargv, ret, restobj;
        struct re *rest;
        bdb_DB *dbst;

        restobj = Data_Make_Struct(obj, struct re, 0, free, rest);
        rest->re_len = -1;
        rest->re_pad = -1;
        if (argc && TYPE(argv[argc - 1]) == T_HASH) {
            rb_iterate(rb_each, argv[argc - 1], bdb_queue_i_search_re_len, restobj);
            if (rest->re_len <= 0) {
                rest->re_len = DEFAULT_RECORD_LENGTH;
                rb_hash_aset(argv[argc - 1], rb_tainted_str_new2("set_re_len"), INT2NUM(rest->re_len));
            }
            if (rest->re_pad < 0) {
                rest->re_pad = DEFAULT_RECORD_PAD;
                rb_hash_aset(argv[argc - 1], rb_tainted_str_new2("set_re_pad"), INT2NUM(rest->re_pad));
            }
            nargv = argv;
        }
        else {
            nargv = ALLOCA_N(VALUE, argc + 1);
            MEMCPY(nargv, argv, VALUE, argc);
            nargv[argc] = rb_hash_new();
            rest->re_len = DEFAULT_RECORD_LENGTH;
            rest->re_pad = DEFAULT_RECORD_PAD;
            rb_hash_aset(nargv[argc], rb_tainted_str_new2("set_re_len"), INT2NUM(DEFAULT_RECORD_LENGTH));
            rb_hash_aset(nargv[argc], rb_tainted_str_new2("set_re_pad"), INT2NUM(DEFAULT_RECORD_PAD));
            argc += 1;
        }
        ret = bdb_s_new(argc, nargv, obj);
        Data_Get_Struct(ret, bdb_DB, dbst);
        dbst->re_len = rest->re_len;
        dbst->re_pad = rest->re_pad;
        return ret;
    }

### Public Instance Methods

<<(p1) click to toggle source

    static VALUE
    bdb_append(obj, val)
        VALUE val, obj;
    {
        return bdb_append_internal(1, &val, obj, DB_APPEND, Qfalse);
    }

each_index(*args) click to toggle source

    VALUE
    bdb_each_key(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_each_kvc(argc, argv, obj, DB_NEXT, Qfalse, BDB_ST_KEY);
    }

pad() click to toggle source

    static VALUE
    bdb_queue_padlen(obj)
        VALUE obj;
    {
        bdb_DB *dbst;
        DB_QUEUE_STAT *bdb_stat;
        VALUE hash;
        char pad;
    #if HAVE_DB_STAT_4_TXN
        DB_TXN *txnid = NULL;
    #endif

        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, 0));
    #else
        bdb_test_error(dbst->dbp->stat(dbst->dbp, &bdb_stat, 0, 0));
    #endif
    #else
        bdb_test_error(dbst->dbp->stat(dbst->dbp, &bdb_stat, 0));
    #endif
        pad = (char)bdb_stat->qs_re_pad;
        hash = rb_assoc_new(rb_tainted_str_new(&pad, 1), INT2NUM(bdb_stat->qs_re_len));
        free(bdb_stat);
        return hash;
    }

push(*args) click to toggle source

    static VALUE
    bdb_append_m(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_append_internal(argc, argv, obj, DB_APPEND, Qtrue);
    }

shift() click to toggle source

    static VALUE
    bdb_consume(obj)
        VALUE obj;
    {
        bdb_DB *dbst;
        DB_TXN *txnid;
        DBT key, data;
        DBC *dbcp;
        int ret;
        db_recno_t recno;

        rb_secure(4);
        INIT_TXN(txnid, obj, dbst);
        MEMZERO(&key, DBT, 1);
        MEMZERO(&data, DBT, 1);
        recno = 1;
        key.data = &recno;
        key.size = sizeof(db_recno_t);
        bdb_test_error(dbst->dbp->cursor(dbst->dbp, txnid, &dbcp, 0));
        bdb_cache_error(dbcp->c_get(dbcp, &key, &data, DB_CONSUME),
                        dbcp->c_close(dbcp), ret);
        dbcp->c_close(dbcp);
        if (ret == DB_NOTFOUND) {
            return Qnil;
        }
        return bdb_assoc(obj, &key, &data);
    }

stat(p1 = v1) click to toggle source

    static VALUE
    bdb_queue_stat(int argc, VALUE *argv, VALUE obj)
    {
        bdb_DB *dbst;
        DB_QUEUE_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("qs_magic"), INT2NUM(bdb_stat->qs_magic));
        rb_hash_aset(hash, rb_tainted_str_new2("qs_version"), INT2NUM(bdb_stat->qs_version));
    #if HAVE_ST_DB_QUEUE_STAT_QS_NKEYS
        rb_hash_aset(hash, rb_tainted_str_new2("qs_nkeys"), INT2NUM(bdb_stat->qs_nkeys));
    #if ! HAVE_ST_DB_QUEUE_STAT_QS_NRECS
        rb_hash_aset(hash, rb_tainted_str_new2("qs_nrecs"), INT2NUM(bdb_stat->qs_nkeys));
    #endif
    #endif
    #if HAVE_ST_DB_QUEUE_STAT_QS_NDATA
        rb_hash_aset(hash, rb_tainted_str_new2("qs_ndata"), INT2NUM(bdb_stat->qs_ndata));
    #endif
    #if HAVE_ST_DB_QUEUE_STAT_QS_NRECS
        rb_hash_aset(hash, rb_tainted_str_new2("qs_nrecs"), INT2NUM(bdb_stat->qs_nrecs));
    #endif
        rb_hash_aset(hash, rb_tainted_str_new2("qs_pages"), INT2NUM(bdb_stat->qs_pages));
        rb_hash_aset(hash, rb_tainted_str_new2("qs_pagesize"), INT2NUM(bdb_stat->qs_pagesize));
        rb_hash_aset(hash, rb_tainted_str_new2("qs_pgfree"), INT2NUM(bdb_stat->qs_pgfree));
        rb_hash_aset(hash, rb_tainted_str_new2("qs_re_len"), INT2NUM(bdb_stat->qs_re_len));
        pad = (char)bdb_stat->qs_re_pad;
        rb_hash_aset(hash, rb_tainted_str_new2("qs_re_pad"), rb_tainted_str_new(&pad, 1));
    #if HAVE_ST_DB_QUEUE_STAT_QS_START
        rb_hash_aset(hash, rb_tainted_str_new2("qs_start"), INT2NUM(bdb_stat->qs_start));
    #endif
        rb_hash_aset(hash, rb_tainted_str_new2("qs_first_recno"), INT2NUM(bdb_stat->qs_first_recno));
        rb_hash_aset(hash, rb_tainted_str_new2("qs_cur_recno"), INT2NUM(bdb_stat->qs_cur_recno));
        free(bdb_stat);
        return hash;
    }