[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes
JS with HASH fast Immutable
2023-09-14 08:59:20 时间
While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's content. If two iterables have the same content, their hash codes will be the same. It's worth noting that this technique is unsuitable for mission critical application development since there is a chance, however slight, that checksums like these might collide. This is outlined here: https://en.wikipedia.org/wiki/Collision_(computer_science)
mocha.setup('bdd'); const expect = chai.expect; class Todo { constructor(title="", items=Immutable.List(), completed=false) { this.id = (+new Date() + Math.floor(Math.random() * 999999)).toString(36); this.title = title; this.items = items; this.completed = completed; } } function generateTodos() { const todos = [] _.each(_.range(5), index => { var todo = new Todo(`Todo ${index}`); todo.completed = Math.round(Math.random()) === 0; _.each(_.range(Math.floor(Math.random()*100)), index => { todo.items = todo.items.push(`Item ${index}`); }); todos.push(todo); }); return todos; } describe('Lightning Fast Equality checks with Hash Codes', () => { it('should take separate lists with the same items and see equal hash codes', () => { var todos = generateTodos(); let todos1 = Immutable.List.of(...todos); let todos2 = Immutable.List.of(...todos); expect(todos1).to.not.equal(todos2); expect(todos1.hashCode()).to.equal(todos2.hashCode()); }); }); mocha.run();
相关文章
- Fabric.js 使用纯色遮挡画布(前景色)
- js面试题及答案2020_JS面试题大全
- node.js(2)
- php 中js跳转页面跳转页面,js跳转代码_PHP页面跳转 Js页面跳转代码[通俗易懂]
- leetcode 3. 无重复字符的最长子串 js 实现
- 如何使用jscythe并通过Node.js的Inspector机制执行任意JS代码
- JS &&、||、!逻辑运算符及用法
- js连接oracle实现数据库访问的简单方法(js怎样连接oracle)
- 分析学习Oracle深入理解使用With 分析(oracle使用with)
- Oracle中使用JS变量管理数据(oracle使用js变量)
- js的with语句使用方法
- JS创建对象(常见的几种方法)
- js对象之JS入门之Array对象操作小结
- Node.js:Windows7下搭建的Node.js服务(来玩玩服务器端的javascript吧,这可不是前端js插件)
- 打开新窗口关闭当前页面不弹出关闭提示js代码
- JS实现的省份级联实例代码
- JS实现导航栏悬停效果
- js修改input的type属性问题探讨
- js算法中的排序、数组去重详细概述
- js中的replace方法使用介绍
- js实现ArrayList功能附实例代码
- js对象基础实例分析