Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dovyih/x-tree-diff-plus

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dovyih/x-tree-diff-plus

A implementation for *X-tree Diff +: An Efficient Change Detection Algorithm for Tree-structured Data*

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-81.25%
Maintainers
1
Weekly downloads
 
Created
Source

x-tree-diff-plus

X-Tree Diff+ alogrithm. PDF

Data Structure

XTree

propertydescription
idnode id
labelNode Label
typeNode Type. Text or Element
valueText Node value
indexNode index
nMDnode message digest
tMDtree mssage digest
iMDnode Id message digest, uniquely identify each node
nPtrnode pointer to matched node
Opedit operation
dataextra data field, you can assign origin Node here

Usage

You need implement XTreeDiffPlus#buildTree and XTreeDiffPlus#dumpTree first.

Like this:

import { XTreeDiffPlus, XTree } from '@dovyih/x-tree-diff-plus';
class DefaultXTreeDiff extends XTreeDiffPlus<XTree, string> {
  public buildXTree(tree: XTree) {
    return tree;
  }
  
  public dumpXTree(oldTree: XTree<string>, newTree: XTree<string>): { oldTree: XTree<string>, newTree: XTree<string>} {
    return { oldTree, newTree };
  }
}

// <A>
//   <B></B>
//   <B></B>
// </A>
const tree1 = new XTree<string>({
    label: 'A',
    type: NodeType.ELEMENT,
    index: 1,
    id: 'a1',
    data: 'tree2-level-1-a-1',
    children: [
      new XTree<string>({
        label: 'B',
        type: NodeType.ELEMENT,
        index: 1,
        id: 'b1',
        data: 'tree2-level-2-b-1',
      }),
      new XTree<string>({
        label: 'B',
        type: NodeType.ELEMENT,
        index: 2,
        id: 'b2',
        data: 'tree2-level-2-b-2',
      }),
    ],
  });


// <A>
//   <B></B>
//   <C></C>
// </A>
const tree2 =  new XTree<string>({
    label: 'A',
    type: NodeType.ELEMENT,
    index: 1,
    id: 'a1',
    data: 'tree2-level-1-a-1',
    children: [
      new XTree<string>({
        label: 'B',
        type: NodeType.ELEMENT,
        index: 1,
        id: 'b1',
        data: 'tree2-level-2-b-1',
      }),
      new XTree<string>({
        label: 'C',
        type: NodeType.ELEMENT,
        index: 2,
        id: 'c2',
        data: 'tree2-level-2-b-2',
      }),
    ],
  });
}

new DefaultXTreeDiff(tree1, tree2).diff();
// result:
//
// <A Op=NOP>
//   <B Op=NOP></B>
//   <B Op=UPD></B>
// </A>
//
// <A Op=NOP>
//   <B Op=NOP></B>
//   <C Op=UPD></C>
// </A>

API

API

Keywords

FAQs

Package last updated on 29 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc