Compare commits
3 Commits
d55ffc4ab3
...
7b11eb7313
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 7b11eb7313 | |
Vitaliy Filippov | 2dacc1b5a7 | |
Vitaliy Filippov | 73ff8c6406 |
|
@ -1,3 +1,5 @@
|
|||
const { select_murmur3 } = require('./murmur3.js');
|
||||
|
||||
const NO_OSD = 'Z';
|
||||
|
||||
class RuleCombinator
|
||||
|
@ -250,7 +252,8 @@ 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);
|
||||
selected.push(select_murmur3(filtered, 'p:'+f.id));
|
||||
const idx = select_murmur3(filtered.length, i => 'p:'+f.id+':'+filtered[i].id);
|
||||
selected.push(idx == null ? { levels: {}, id: null } : filtered[idx]);
|
||||
}
|
||||
const size = selected.filter(s => s.id !== null).length;
|
||||
max_size = max_size < size ? size : max_size;
|
||||
|
@ -266,7 +269,8 @@ 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;
|
||||
selected.push(select_murmur3(filtered, n));
|
||||
const idx = select_murmur3(filtered.length, i => n+':'+filtered[i].id);
|
||||
selected.push(idx == null ? { levels: {}, id: null } : filtered[idx]);
|
||||
}
|
||||
const size = selected.filter(s => s.id !== null).length;
|
||||
max_size = max_size < size ? size : max_size;
|
||||
|
@ -286,40 +290,6 @@ 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;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
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