Giter VIP home page Giter VIP logo

judy-template's People

Contributors

mpictor avatar starseeker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

judy-template's Issues

Seems there are incorrect result?

The code here from this folder, note on this blog. Stackoverflow question here.

// judy.cpp
#include "deps/judySArray.h"
#include <string>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef judySArray<double> MSD;
const int MAX_DATA = 12000000;
const char i2ch[] = {'0','1','2','3','4','5','6','7','8','9','a','B','c','D','e','F'};
int get_first_digit(double d) {
    while(d > 10) d /= 10;
    return d;
}
string to_rhex(int v) {
    char hex[32];   
    int start = 0;
    while(v>0) {
        hex[start] = i2ch[v%16];
        v /= 16;
        ++start;
    }
    hex[start] = 0;
    return hex;
}
void add_or_inc(MSD &m, const string& key,double set, double inc, int& ctr) {
    const char* cstr = key.c_str();
    double it = m.find(cstr);
    if(!it) {
        m.insert(cstr,set);
        return;
    }
    m.insert(cstr,it+inc);
    ++ctr;
}
int main() {
    MSD m(64);  
    int dup1 = 0, dup2 = 0, dup3 = 0;
    for(int z=MAX_DATA;z>0;--z) {
        int val2 = MAX_DATA-z;
        int val3 = MAX_DATA*2-z;
        string key1 = to_string(z);
        string key2 = to_string(val2);
        string key3 = to_rhex(val3);
        add_or_inc(m,key1,z,val2,dup1);
        add_or_inc(m,key2,val2,val3,dup2);
        add_or_inc(m,key3,val3,z,dup3);
    }
    cout << dup1 << ' ' << dup2 << ' ' << dup3 << endl;
    int total = 0, verify = 0, count = 0;
    for(auto &it = m.begin();m.success(); m.next()) {
        total += get_first_digit(it.value); 
        verify += strlen((const char *) it.key);
        count += 1;
    }
    cout << total << ' ' << verify << ' ' << count << endl;
}

other implementation (map, unordered_map, hat-trie and cedar) give correct result:

6009354 6009348 611297
36186112 159701682 23370001

but judy didn't:

6009354 6009348 611297
36186112 159701681 23370000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.