Git Product home page Git Product logo

Comments (1)

Henry-Diasa avatar Henry-Diasa commented on July 20, 2024

Diff算法就是为了找不同然后执行更新的操作,严格的比较两棵树的时间复杂度是O(n ^ 3)

diff的时候涉及到一些优化,降低到O(n)

  • 只同层级比较,不跨层比较
  • tag不同则删除重建(不比较内部的细节)
  • 子节点通过key区分

React - 仅右移

新节点和旧节点比较时,老节点仅右移(新的索引大于老的索引)

image

Vue2 - 双端比较

注意四个指针,分别前后比较,交叉比较。

image

Vue3 - 最长递增子序列

例如 [3, 5, 7, 1, 2, 8] 最长递增 [3, 5, 7, 8] (也可以看看leetcode里面的算法)

比较过程首先和vue2一样 前后和交叉比较, 最终的索引所构成的最长递增子序列是 [2, 3, 4] 所以这三个节点就不需要改变了。最大程度减少dom的操作

image

from awesome_interview_question.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.