求模优化
- 已知 bucket 长度 n,求目标 m 在 n 的位置
int index = n % m;- 普通求余
int index = (int) (m & (n - 1));- 在
n为 2 的幂的前提下,使用位操作进行优化
- 在
mybatis 批量更新
- 这里仅记录 foreach
<update id="updateRecordList"><!--这里是拼接一大串 update 语句,所以 separator 用的是分号注意数据包过大导致异常--><foreach collection="poList" separator=";" item="item">UPDATE c_broadcast_mail_record<set><if test="item.read != null">`read` = #{item.read},</if><if test="item.attachmentState">`attachment_state` = #{item.attachmentState},</if><if test="item.deleted">`deleted` = #{item.deleted}</if></set>WHERE `receiver_id` = #{item.receiverId} and `broadcast_mail_id` = #{item.broadcastMailId}</foreach></update>
Collections.binarySearch
- 有三个参数,第三个参数是个比较器
- 我 jio 得要注意一下
- 如果集合元素没有实现
Comparable,那么要集合本身要通过同一个比较器进行排序,然后再通过这个排序进行查找 - 如果集合元素实现了
Comparable,那么查找的时候就会通过元素本身来判断了
- 如果集合元素没有实现
- 内部实现中
- 如果是
Random接口的集合,那么是通过索引进行比较,很快 - 其他的用 Iterator 进行比较
- 如果是
