MCPcopy Create free account
hub / github.com/apache/mesos / buildTree

Function buildTree

src/webui/app/app.js:277–299  ·  view source on GitHub ↗
(roles)

Source from the content-addressed store, hash-verified

275 // {'a': {'.': {}, 'b' : {}}, 'e': {'f': {}, 'g': '{}'}}
276 // (corresponding paths are 'a/.', 'a/b', 'e/f' and 'e/g')
277 function buildTree(roles) {
278 var root = {};
279
280 for (var roleIndex = 0; roleIndex < roles.length; roleIndex += 1) {
281 var tokens = roles[roleIndex].split('/');
282 var i = 0;
283 var node = root;
284 for (i = 0; i < tokens.length && (tokens[i] in node); i += 1) {
285 node = node[tokens[i]];
286 }
287
288 if (i > 0 && (i == tokens.length || Object.keys(node).length == 0)) {
289 node['.'] = {};
290 }
291
292 for (; i < tokens.length; i += 1) {
293 node[tokens[i]] = {};
294 node = node[tokens[i]];
295 }
296 }
297
298 return root;
299 }
300
301 function prepareTree(path, name, node) {
302 var prefix = path ? path + '/' : '';

Callers 2

foreachFunction · 0.85
app.jsFile · 0.85

Calls 1

keysMethod · 0.45

Tested by 1

foreachFunction · 0.68