Esempio n. 1
0
/* adddouble */
JNIEXPORT jdouble JNICALL Java_tokyocabinet_BDB_adddouble
(JNIEnv *env, jobject self, jbyteArray key, jdouble num){
  if(!key){
    throwillarg(env);
    return 0.0;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return 0.0;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  num = tcbdbadddouble(bdb, kbuf, ksiz, num);
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return num;
}
Esempio n. 2
0
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
        TCCMP cmp, int omode, int dmode) {
    TCBDB *bdb = tcbdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
    if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
    if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
    if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
        printerr(bdb);
        tcbdbdel(bdb);
        return 1;
    }
    bool err = false;
    int inum;
    double dnum;
    switch (dmode) {
        case -1:
            if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(bdb);
                err = true;
            }
            break;
        case 1:
            if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(bdb);
                err = true;
            }
            break;
        case 2:
            if (!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(bdb);
                err = true;
            }
            break;
        case 3:
            if (!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(bdb);
                err = true;
            }
            break;
        case 10:
            inum = tcbdbaddint(bdb, kbuf, ksiz, tcatoi(vbuf));
            if (inum == INT_MIN) {
                printerr(bdb);
                err = true;
            } else {
                printf("%d\n", inum);
            }
            break;
        case 11:
            dnum = tcbdbadddouble(bdb, kbuf, ksiz, tcatof(vbuf));
            if (isnan(dnum)) {
                printerr(bdb);
                err = true;
            } else {
                printf("%.6f\n", dnum);
            }
            break;
        default:
            if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(bdb);
                err = true;
            }
            break;
    }
    if (!tcbdbclose(bdb)) {
        if (!err) printerr(bdb);
        err = true;
    }
    tcbdbdel(bdb);
    return err ? 1 : 0;
}