Changeset 25440


Ignore:
Timestamp:
2012-04-19T16:09:40+12:00 (12 years ago)
Author:
sjm84
Message:

Adding a hashing function (replica of our cpp version)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/oran/js/javascript-global-functions.js

    r25364 r25440  
    233233function ifposDec(a, b)
    234234{
    235     console.log("GOT " + a + " and " + b);
    236235    var carry = 0;
    237236    var num = 0;
    238237    var i = 0;
    239238   
    240     if(b.length > a.length){console.log("RETURNING 0 (1)"); return 0;}
     239    if(b.length > a.length){return a;}
    241240    if(b.length == a.length)
    242241    {
     
    244243        while(i >= 0)
    245244        {
    246             if(a[i] > b[i]){console.log("BREAKING"); break;}
    247             if(a[i] < b[i]){console.log("RETURNING 0 (2)"); return 0;}
     245            if(a[i] > b[i]){break;}
     246            if(a[i] < b[i]){return a;}
    248247            i--;
    249248        }
     
    251250   
    252251    i = 0;
     252    var len = 0;
     253    var outString = "";
    253254    while((i < a.length) || (i < b.length))
    254255    {
     
    268269       
    269270        a[i] = num;
     271        outString += num + ","
    270272        i++
    271     }
    272     console.log("NUM is " + num);
    273    
    274     return 1;
     273       
     274        if(num != 0){len = i}
     275    }
     276
     277    if(len < a.length)
     278    {
     279        a = a.slice(0, len);
     280    }
     281   
     282    return a;
    275283}
    276284
     
    289297    for(i = a.length - 1; i >= 0; i--)
    290298    {
    291         console.log("i is " + i + " a[i] is " + a[i] + " a[i]/16 is " + Math.floor(a[i]/16) + " a[i]%16 is " + Math.floor(a[i]%16));
    292         console.log("Adding " + convert[Math.floor(a[i]/16)] + " and " + convert[Math.floor(a[i]%16)]);
    293299        result.push(convert[Math.floor(a[i]/16)]);
    294300        result.push(convert[Math.floor(a[i]%16)]);
     
    318324    for(var i = 0; i < 8; i++)
    319325    {
    320         primePow.push(pow);
     326        primePow.push(pow.slice()); //The javascript way to do an array copy (yuck!)
    321327        inc(pow, pow);
    322328    }
     
    324330    for(var i = 0; i < str.length; i++)
    325331    {
    326         var c = str.charAt(i);
     332        var c = str.charCodeAt(i);
    327333
    328334        if(remainder.length == 99)
     
    333339        for(var j = remainder.length; j > 0; j--)
    334340        {
    335             remainder[i] = remainder[i-1];
     341            remainder[j] = remainder[j-1];
    336342        }
    337343        remainder[0] = c;
     
    339345        for(var j = 7; j >= 0; j--)
    340346        {
    341             ifposDec(remainder, primePow[j]);
     347            remainder = ifposDec(remainder, primePow[j]);
    342348        }   
    343349    }
    344    
    345     var returnString = remainder.length + " AWAY TO CONVERT -> ";
    346     for(var i = 0; i < remainder.length; i++)
    347     {
    348         returnString += remainder[i] + " ";
    349     }
    350     console.log(returnString);
    351350   
    352351    return convertNum(remainder);
Note: See TracChangeset for help on using the changeset viewer.