- 浏览: 3412298 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
http://my.oschina.net/android520/blog/700738
Comparable接口,只要类继承该接口,就可以实现对象的排序功能。
Comparator接口,可以用来对已有的未继承Comparable接口的,进行排序。
sort方法,在JDK6和JDK7中实现方式不一样,具体如下:
来自http://blog.sina.com.cn/s/blog_8e6f1b330101h7fa.html
在Java 6中Arrays.sort()和Collections.sort()使用的是MergeSort,而在Java 7中,内部实现换成了TimSort,其对对象间比较的实现要求更加严格:
Comparator的实现必须保证以下几点(出自这儿):
a). sgn(compare(x, y)) == -sgn(compare(y, x))
b). (compare(x, y)>0) && (compare(y, z)>0) 意味着 compare(x, z)>0
c). compare(x, y)==0 意味着对于任意的z:sgn(compare(x, z))==sgn(compare(y, z)) 均成立
而我们的代码中,某个compare()实现片段是这样的:
这就违背了a)原则:假设X的value为1,Y的value也为1;那么compare(X, Y) ≠ –compare(Y, X)
PS: TimSort不仅内置在各种JDK 7的版本,也存在于Android SDK中(尽管其并没有使用JDK 7)。
下面看下sort方法中的具体排序源码
从代码中可以看出使用的是二分法排序binarySort
public class ComparableUser implements Comparable<Object> { public String name; public int age; public ComparableUser(String name, int age) { this.name = name; this.age = age; } @Override public int compareTo(Object o) { return age - ((ComparableUser) o).age; } } ComparableUser[] users = new ComparableUser[] { new ComparableUser("Jim", 80), new ComparableUser("Tom", 10), new ComparableUser("Lily", 30), new ComparableUser("Marry", 20) }; Arrays.sort(users);
Comparable接口,只要类继承该接口,就可以实现对象的排序功能。
public class User { public String name; public int age; public User(String name, int age) { this.name = name; this.age = age; } } public class ComparatorUser implements Comparator<User> { @Override public int compare(User o1, User o2) { return o1.age - o2.age; } } User[] users2 = new User[] { new User("Jim", 80), new User("Tom", 10), new User("Lily", 30), new User("Marry", 20) }; Arrays.sort(users2, new ComparatorUser());
Comparator接口,可以用来对已有的未继承Comparable接口的,进行排序。
sort方法,在JDK6和JDK7中实现方式不一样,具体如下:
来自http://blog.sina.com.cn/s/blog_8e6f1b330101h7fa.html
在Java 6中Arrays.sort()和Collections.sort()使用的是MergeSort,而在Java 7中,内部实现换成了TimSort,其对对象间比较的实现要求更加严格:
Comparator的实现必须保证以下几点(出自这儿):
a). sgn(compare(x, y)) == -sgn(compare(y, x))
b). (compare(x, y)>0) && (compare(y, z)>0) 意味着 compare(x, z)>0
c). compare(x, y)==0 意味着对于任意的z:sgn(compare(x, z))==sgn(compare(y, z)) 均成立
而我们的代码中,某个compare()实现片段是这样的:
public int compare(ComparatorTest o1, ComparatorTest o2) { return o1.getValue() > o2.getValue() ? 1 : -1; }
这就违背了a)原则:假设X的value为1,Y的value也为1;那么compare(X, Y) ≠ –compare(Y, X)
PS: TimSort不仅内置在各种JDK 7的版本,也存在于Android SDK中(尽管其并没有使用JDK 7)。
下面看下sort方法中的具体排序源码
static void sort(Object[] a, int lo, int hi) { rangeCheck(a.length, lo, hi); int nRemaining = hi - lo; if (nRemaining < 2) return; // Arrays of size 0 and 1 are always sorted // If array is small, do a "mini-TimSort" with no merges if (nRemaining < MIN_MERGE) { int initRunLen = countRunAndMakeAscending(a, lo, hi); binarySort(a, lo, hi, lo + initRunLen); return; } ............................ }
从代码中可以看出使用的是二分法排序binarySort
/** * Sorts the specified portion of the specified array using a binary * insertion sort. This is the best method for sorting small numbers * of elements. It requires O(n log n) compares, but O(n^2) data * movement (worst case). * * If the initial part of the specified range is already sorted, * this method can take advantage of it: the method assumes that the * elements from index {@code lo}, inclusive, to {@code start}, * exclusive are already sorted. * * @param a the array in which a range is to be sorted * @param lo the index of the first element in the range to be sorted * @param hi the index after the last element in the range to be sorted * @param start the index of the first element in the range that is * not already known to be sorted ({@code lo <= start <= hi}) */ @SuppressWarnings("fallthrough") private static void binarySort(Object[] a, int lo, int hi, int start) { assert lo <= start && start <= hi; if (start == lo) start++; for ( ; start < hi; start++) { @SuppressWarnings("unchecked") Comparable<Object> pivot = (Comparable) a[start]; // Set left (and right) to the index where a[start] (pivot) belongs int left = lo; int right = start; assert left <= right; /* * Invariants: * pivot >= all in [lo, left). * pivot < all in [right, start). */ while (left < right) { int mid = (left + right) >>> 1; if (pivot.compareTo(a[mid]) < 0) right = mid; else left = mid + 1; } assert left == right; /* * The invariants still hold: pivot >= all in [lo, left) and * pivot < all in [left, start), so pivot belongs at left. Note * that if there are elements equal to pivot, left points to the * first slot after them -- that's why this sort is stable. * Slide elements over to make room for pivot. */ int n = start - left; // The number of elements to move // Switch is just an optimization for arraycopy in default case switch (n) { case 2: a[left + 2] = a[left + 1]; case 1: a[left + 1] = a[left]; break; default: System.arraycopy(a, left, a, left + 1, n); } a[left] = pivot; } }
发表评论
-
Java集合框架之fastutil & koloboke
2016-06-23 14:04 2462Java集合框架之fastutil http://rensan ... -
ehcache 分布式支持
2016-06-05 22:26 1094原文 http://my.oschina.net/glenxu ... -
Intellij IDEA插件开发入门
2016-05-26 11:42 2877原文: http://blog.csdn.net/dc_726 ... -
阿里巴巴Druid数据源的配置与使用
2016-05-24 17:42 1534http://my.oschina.net/wjme/blog ... -
mysql中间件研究(Atlas,cobar,TDDL), 分库分表插件
2016-05-09 14:15 3435http://www.guokr.com/blog/47576 ... -
Java集合: Queue和Deque
2016-05-09 09:49 1858Queue http://my.oschina.net/kev ... -
使用gzip优化web应用(filter实现)
2016-05-07 01:45 1025使用gzip优化web应用(filter实现) http:// ... -
Byteman 3.0.5 发布,Java 字节码注入工具
2016-04-23 10:29 1763Byteman 3.0.5 发布,Java 字 ... -
RandomStringUtils的说明和生成随机汉字
2016-04-20 15:21 1372更多参考: http://my.oschina.net/wil ... -
通过IP地址获取地理位置
2016-04-20 15:19 887http://my.oschina.net/githubhty ... -
Java编程中使用正则表达式过滤非数字字符串
2016-04-14 13:51 1708/** * * @param str ... -
非对称加密DH算法,DH代码实现
2016-04-13 11:33 1350RSA算法原理(一)http:// ... -
企业支付宝账号开发接口教程
2016-03-31 14:52 1227企业支付宝账号开发接口教程--JAVA-UTF-8(实际操作- ... -
java double类型数据操作工具类
2016-03-28 17:36 1227http://my.oschina.net/yxwblog/b ... -
double转换到BigDecimal
2016-03-28 17:11 1538BigDecimal b = new BigDecimal(d ... -
Java 生成好看的验证码
2016-03-23 10:52 3351http://www.oschina.net/code/sni ... -
Linux环境安装配置Swftools
2016-03-22 21:01 1094http://tetop.blog.51cto.com/188 ... -
java压缩与解压缩文件
2016-03-20 22:03 1464http://www.oschina.net/code/sni ... -
java图像压缩
2016-03-19 23:20 945http://my.oschina.net/686991/bl ... -
会话状态保持,JSESSIONID,COOKIE,URL重写
2016-03-17 20:26 1758http://my.oschina.net/sniperLi/ ...
相关推荐
【作品名称】:基于MATLAB的肤色的人数统计系统,以地铁车厢为实际背景,通过预测的方式,结合肤色统计人脸得到车厢人数,从而估计拥挤度 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】:该课题为基于MATLAB的肤色的人数统计系统,以地铁车厢为实际背景,通过预测的方式,结合肤色统计人脸得到车厢人数,从而估计拥挤度,将结果反馈给车站里的视频,让乘客得知每节车厢的拥挤程度,从而合理分配车厢乘客,避免资源浪费和拥挤,本设计带有一个GUI交互界面。是一个人数统计类课题,该课题可以应用于教室人数统计,十字路口行人统计等等方面。 【资源声明】:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。
亲爱的工程师和技术爱好者们, 您是否想学习一种强大的图形化编程语言,以便在自动化、数据采集、测试测量等领域大展身手?LabVIEW 是您的最佳选择!我们为您精心准备了一份全面的 LabVIEW 入门教程,帮助您从零开始,逐步掌握这门强大的工具。 为什么选择 LabVIEW? 直观易学:图形化编程界面,无需编写复杂的代码。 广泛应用:适用于工业自动化、数据采集、仪器控制、图像处理等多个领域。 强大功能:内置丰富的函数库和工具包,满足各种复杂需求。 社区支持:庞大的用户社区和丰富的在线资源,助您解决各种问题。 本教程适合谁? 初学者:从未接触过 LabVIEW 的新手。 工程师:希望提升技能,提高工作效率的专业人士。 学生:对自动化和测试测量感兴趣的在校学生。 研究人员:需要进行数据采集和分析的研究人员。 课程内容 LabVIEW 基础:安装与配置、界面介绍、基本概念。 图形化编程:创建 VI(虚拟仪器)、使用控件和指示器。 数据流编程:理解数据流的概念,编写简单的程序。 常用函数库:了解并使用常用
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
离网下三相不平衡负载,基于下垂控制的T型三电平逆变器,采用正负序分离四环控制,正序电压电流双闭环,负序电压电流双闭环,中点电位平衡控制,采用SPWM调制。 1.提供下垂控制原理,参数计算方法以及相关文献 2.电压电流双闭环控制 3.正负序分离控制以及相关资料 支持simulink2022以下版本(默认发2016b)。
微信小程序-新闻阅读器_ echatapp新闻阅读器
该项目是一个基于Python和HTML的TDXPystock股票交易自动化设计源码,总共有72个文件组成,包括47个Python源文件、6个XML配置文件、6个文本文件、3个用户界面文件、1个Git忽略文件、1个IDE配置文件、1个Jupyter Notebook文件、1个Markdown文件、1个SQL文件和1个图片文件。该项目旨在通过编程手段实现股票交易自动化,适用于对股票市场感兴趣的开发者和投资者。
c
微信OpenDevTool-微信小程序强制开发者工具打开-WiChatOpenDevTools Python
内容概要:本文提供了C++实现的一个基本汽车自动驾驶巡航系统。这个例子涵盖了系统的基础元素:模拟汽车自动巡航的定义、设定巡航的速度等功能,并在一个无限的回圈下演示了时间和速度的流动。 适合人群:适合熟悉 C++ 开发人员,尤其对车辆自动化感兴趣的研究者们。 使用场景及目标:旨在帮助开发者快速建立关于自动驾驶巡航系统的原型,加深对其基本特性的理解和认识。
ClioSoft SOS 8.1.1 2023最新版手册
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
STM32硬件液晶资料OLED资料STM32硬件液晶资料OLED资料
C# 矩阵运算类库 矩阵运算,求逆 。 欧拉角转类库 。 24种欧拉角、四元数互相转 数学运算100%正确无措
本文提供了一份采用C语言实现智能小车自动化移动的基本实例源码。通过对左旋/右旋、正向推进、逆向后移以及停止等一系列指令的具体阐述及注释指引,详述各命令的工作机理与实施程序。该文档为智能设备的研发与实践,特别是围绕小型自主驱动载具的设计与构建提供了有益启示,还介绍了怎样配合特定硬件来设置相应的端口标识符并引入传感器增强自动寻径效果,如防碰撞能力。 适用人群:掌握一定的嵌入式系统的编程能力的研究开发者或学生;适用于对Arduino平台有初步操作经验且有兴趣进一步探索其机器人领域的爱好者。 使用场景及目标:对于想要从基础开始动手做智能巡线车项目的电子爱好人士来说,这是一个很好的起点,旨在让小车模拟简单的自动驾驶行为(例如绕固定路径行驶),并为加入更多的智能化组件留有足够的扩展空间。 其它注意事项:注意,代码里运用到wiringPi库,请先行验证它已经顺利装妥和匹配系统。同时也要记得依照自己的物理接驳图更改代码里面的电机对应关系。
微信小程序反编译脚本备份WaxAppUnpacker
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
WelCropper微信小程序截图工具_ WelCropper
微信小程序反编译工具w_xappUnpacker
STM32软件学习资料USBSTM32软件学习资料USB