[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes
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();
[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes的更多相关文章
- [Javascript] Creating an Immutable Object Graph with Immutable.js Map()
Learn how to create an Immutable.Map() through plain Javascript object construction and also via arr ...
- Node.js学习笔记——Node.js开发Web后台服务
一.简介 Node.js 是一个基于Google Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效.Node.j ...
- Node.js系列之node.js初探
官方介绍:Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable n ...
- H5案例分享:JS手势框架 —— Hammer.js
JS手势框架 -- Hammer.js 一.hammer.js简介 hammerJS是一个开源的,轻量级的触屏设备javascript手势库,它可以在不需要依赖其他东西的情况下识别触摸,鼠标事件.允许 ...
- Js的typeof和Js的基本数据类型
本文将从以下几个方面介绍Js的typeof和Js的基本数据类型: ** Js的typeof的用法 ** Js的基本数据类型 ** 使用基本类型使用typeof的返回结果 ** Js的typeof的用法 ...
- js get browser vertion (js获取浏览器信息版本)
1问题:js get browser vertion (js获取浏览器信息版本) 2解决方案 Copy this script into your JavaScript files. It works ...
- 1-7 basket.js localstorage.js缓存css、js
basket.js 源码分析 api 使用文档: http://t3n.de/news/basketjs-performance-localstorage-515119/ 一.前言 b ...
- 【js跨域】js实现跨域访问的几种方式
这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...
- Node.js入门:Node.js&NPM的安装与配置
Node.js安装与配置 Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...
随机推荐
- Win32多线程编程(2) — 线程控制
Win32线程控制只有是围绕线程这一内核对象的创建.挂起.恢复.终结以及通信等操作,这些操作都依赖于Win32操作系统提供的一组API和具体编译器的C运行时库函数.本篇围绕这些操作接口介绍在Windo ...
- tomcat线程数查看
获取tomcat进程pid ps -ef|grep tomcat 统计该tomcat进程内的线程个数 ps -Lf 29295 |wc -l
- js_day13
- python-线程、进程、协程
进程 && 线程 进程:是内存中的一个独立的句柄,我们可以理解为一个应用程序在内存中就是一个进程. 各个进程之间是内存相互独立,不可共享的 线程:每个应用运行之后就会对应启动一个主线程 ...
- Android AsyncTask学习
Android程序有UI进程和后台进程,在执行一些耗时的操作时,如果在UI进程中,很可能出现假死的情况,用户体验会受到影响,因此,那些耗时进程往往就放在了后台进程中,用户体验能更好一些.网络情况不稳定 ...
- 原创:2016.4.25-2016.5.1 C# informal essay and tittle_tattle
1.Some tips of the Time in C sharp (1) How to define the category of the "Datetime"? date ...
- 1、shell 简介
Shell 本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥 梁,用户的大部分工作都是通过Shell完成的.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地 ...
- python中raw_input()与input()
raw_input([prompt]) input([prompt]) # prompt:如果参数存在,直接输出到屏幕上,不会再另起一行 raw_input 如其字面意思一样,返回输入字符的字符串形式 ...
- C++的this指针
这篇博客主要内容翻译自国外著名程序员网站:geekersforgeekers,经过作者小幅度整理,水平有限,敬请指正. 关于this指针的粗浅认识 (一) this指针: 在对象的任意非static类 ...
- HDU 5044 离线LCA算法
昨天写了HDU 3966 ,本来这道题是很好解得,结果我想用离线LCA 耍一把,结果发现离线LCA 没理解透,错了好多遍,终得AC ,这题比起 HDU 3966要简单,因为他不用动态查询.但是我还是错 ...