Compare commits
3 Commits
7b11eb7313
...
d55ffc4ab3
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | d55ffc4ab3 | |
Vitaliy Filippov | b9017d55b0 | |
Vitaliy Filippov | e8989a6ae5 |
|
@ -1,5 +1,3 @@
|
|||
const { select_murmur3 } = require('./murmur3.js');
|
||||
|
||||
const NO_OSD = 'Z';
|
||||
|
||||
class RuleCombinator
|
||||
|
@ -252,8 +250,7 @@ function random_custom_combinations(osd_tree, rules, count, ordered)
|
|||
for (let i = 1; i < rules.length; i++)
|
||||
{
|
||||
const filtered = filter_tree_by_rules(osd_tree, rules[i], selected);
|
||||
const idx = select_murmur3(filtered.length, i => 'p:'+f.id+':'+filtered[i].id);
|
||||
selected.push(idx == null ? { levels: {}, id: null } : filtered[idx]);
|
||||
selected.push(select_murmur3(filtered, 'p:'+f.id));
|
||||
}
|
||||
const size = selected.filter(s => s.id !== null).length;
|
||||
max_size = max_size < size ? size : max_size;
|
||||
|
@ -269,8 +266,7 @@ function random_custom_combinations(osd_tree, rules, count, ordered)
|
|||
for (const item_rules of rules)
|
||||
{
|
||||
const filtered = selected.length ? filter_tree_by_rules(osd_tree, item_rules, selected) : first;
|
||||
const idx = select_murmur3(filtered.length, i => n+':'+filtered[i].id);
|
||||
selected.push(idx == null ? { levels: {}, id: null } : filtered[idx]);
|
||||
selected.push(select_murmur3(filtered, n));
|
||||
}
|
||||
const size = selected.filter(s => s.id !== null).length;
|
||||
max_size = max_size < size ? size : max_size;
|
||||
|
@ -290,6 +286,40 @@ function random_custom_combinations(osd_tree, rules, count, ordered)
|
|||
return r;
|
||||
}
|
||||
|
||||
function select_murmur3(filtered, prefix)
|
||||
{
|
||||
if (!filtered.length)
|
||||
{
|
||||
return { levels: {}, id: null };
|
||||
}
|
||||
else
|
||||
{
|
||||
let i = 0, maxh = -1;
|
||||
for (let j = 0; j < filtered.length; j++)
|
||||
{
|
||||
const h = murmur3(prefix+':'+filtered[j].id);
|
||||
if (h > maxh)
|
||||
{
|
||||
i = j;
|
||||
maxh = h;
|
||||
}
|
||||
}
|
||||
return filtered[i];
|
||||
}
|
||||
}
|
||||
|
||||
function murmur3(s)
|
||||
{
|
||||
let hash = 0x12345678;
|
||||
for (let i = 0; i < s.length; i++)
|
||||
{
|
||||
hash ^= s.charCodeAt(i);
|
||||
hash = (hash*0x5bd1e995) & 0xFFFFFFFF;
|
||||
hash ^= (hash >> 15);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function filter_tree_by_rules(osd_tree, rules, selected)
|
||||
{
|
||||
let cur = osd_tree[''].children;
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
function select_murmur3(count, cb)
|
||||
{
|
||||
if (!count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
let i = 0, maxh = -1;
|
||||
for (let j = 0; j < count; j++)
|
||||
{
|
||||
const h = murmur3(cb(j));
|
||||
if (h > maxh)
|
||||
{
|
||||
i = j;
|
||||
maxh = h;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
function murmur3(s)
|
||||
{
|
||||
let hash = 0x12345678;
|
||||
for (let i = 0; i < s.length; i++)
|
||||
{
|
||||
hash ^= s.charCodeAt(i);
|
||||
hash = (hash*0x5bd1e995) & 0xFFFFFFFF;
|
||||
hash ^= (hash >> 15);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
murmur3,
|
||||
select_murmur3,
|
||||
};
|
Loading…
Reference in New Issue