-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added segment tree to transaction trace
- Loading branch information
Showing
8 changed files
with
211 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const logger = require('../../logger').child({ component: 'segment-tree' }) | ||
|
||
class Node { | ||
constructor(segment) { | ||
this.segment = segment | ||
this.children = [] | ||
} | ||
} | ||
|
||
class SegmentTree { | ||
constructor(root) { | ||
this.root = new Node(root) | ||
} | ||
|
||
find(parentId, node = this.root) { | ||
if (parentId === node.segment.id) { | ||
return node | ||
} | ||
|
||
for (const child of node.children) { | ||
const result = this.find(parentId, child) | ||
if (result) { | ||
return result | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
add(segment) { | ||
const node = new Node(segment) | ||
const parent = this.find(segment.parentId) | ||
|
||
if (!parent) { | ||
logger.debug('Cannot find parent %s in tree', segment.parentId) | ||
return | ||
} | ||
|
||
parent.children.push(node) | ||
} | ||
} | ||
|
||
module.exports = SegmentTree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.