- 博客(193)
- 收藏
- 关注
转载 链表快排
func sortList(head *ListNode) *ListNode { slist(head,nil) return head } func slist(head *ListNode,tail *ListNode){ if head == nil || head.Next == nil || head == tail{ ...
2019-09-25 17:15:00 185
转载 并查集
一共两个函数 find() 查找根节点 union() 合并两个集合 根据树的高度合并两集合 定义一个rank[]数组,存储两个树的高度,比如rank[xroot] = 3 如果rank[xRoot] > rank{yRoot]的时候,就是x那个树比y那个树要高,所以合并的时候将y那个树的根节点给连接到x那个树的根节点下面。 如果rank[xRoot] = r...
2019-09-24 21:36:00 153
转载 二分查找
func findTarget(numbers [] int , target int ,left int) int{ right := len(numbers) - 1 result := -1 for left <= right{ mid := left + (right - left)/2 if numbe...
2019-09-23 09:06:00 171
转载 Go语言集合
ZERO. 数组 1. 创建 一个不固定大小的数组 var array [] int 2. 遍历 var nums1 = []int {1,6,7} for _, n := range nums1{ fmt.Println(n) //输出结果为1,6,7 }for i, n:= range nums1{ fmt.Println(n) ...
2019-09-20 19:49:00 439
转载 快排
func quickSort(nums []int,left int,right int ){ if left < right { p := park(nums,left,right) quickSort(nums,left,p-1) quickSort(nums,p+1,right) } }...
2019-09-20 19:12:00 100
转载 Mysql的一些问题
一. 安装mysql后root shell可以登录但是普通用户不能使用mysql -u root -p登录mysql 解决: 使用root登录 select user,host from mysql.user DROP USER 'root'@'localhost'; CREATE USER 'root'@'%' IDENTIFIED BY 'zhuopeng'...
2019-09-10 09:02:00 90
转载 找到数组中重复的数字
解法1. : 解法2: 快慢指针,环 public int findDuplicate(int[] nums) { int slow = nums[0]; int fast = nums[nums[0]]; while (slow != fast) { s...
2019-09-09 10:53:00 75
转载 gradle
1. gradle clean build 2. gradle wrapper 执行完成这个命令后,会出现一个gradle文件夹,里面有gradle-wrapper.jar和gradle-wrapper.properties 执行完成这两个命令后就可以把 gradle gradle-wrapper.jar gradle-wrapper.proper...
2019-08-29 21:34:00 84
转载 1-NIO使用
1.FileChannel 和 Buffer package nio._Buffer; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.Buffer; import java.nio.By...
2018-12-09 18:31:00 83
转载 处理非正常终止的错误
1. 最简单通过主动的内部函数的方法捕获 package concurrent._ThreadPool._UnnormalThread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; //一种主动的方法捕获异常 public class D...
2018-12-03 10:17:00 213
转载 一个取消多生产者单消费者的日志线程池服务
package concurrent._ThreadPool.logService; import net.jcip.annotations.GuardedBy; import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import java.io.FileNotFoundException; import java....
2018-12-02 11:13:00 86
转载 executes()源码
/** * Executes the given task sometime in the future. The task * may execute in a new thread or in an existing pooled thread. * * If the task cannot be submitted fo...
2018-11-28 15:33:00 135
转载 死锁
死锁 1.通过锁的顺序来避免死锁的发生,比如使用System.identityHashCode()排序,或者源数据中就有可比较的键值,比如账户 package concurrent._deadLock; public class Demo { public static void main(String[] args) { } //模...
2018-11-27 21:18:00 86
转载 CyclicBarrier使用
demo1: package concurrent._Barrier; import java.util.Random; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; public class Demo { pub...
2018-11-27 20:06:00 81
转载 Semaphore
一个有界的容器: /一个有界的集合Set class BoundedhashSet<T> { private final Set<T> set; private final Semaphore sem; public BoundedhashSet(int count) { this.sem = new S...
2018-11-27 19:05:00 82
转载 闭锁CountDownLatch
package concurrent._ReentrantLock; import java.util.concurrent.CountDownLatch; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; //一个关于Lock的最基本操作,...
2018-11-26 21:20:00 92
转载 LockSupport
是一个很简单的类: 底层通过CAS操作实现 public class Demo { public static void main(String[] args) throws InterruptedException { ThreadA a = new ThreadA("a"); a.start(); Thread....
2018-11-26 18:32:00 83
转载 yield
线程的礼让: 当轮到一个线程执行任务,但是这个线程处理一个不是很重要的事情的时候,可以让大家来一次抢占的机会 程序: package concurrent._yield; public class Demo { public static void main(String[] args) { ThreadA a = new ThreadA("a...
2018-11-26 11:35:00 54
转载 Condition
condition.await() condition.signalAll() package concurrent._Condition; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.lo...
2018-11-26 10:49:00 67
转载 AQS的不公平锁源码
同步器节点的waitStatus解释 CANCELLED 取消状态 SIGNAL -1 等待触发状态,前节点可能是head或者前节点为取消状态CANCELLED CONDITION -2 等待条件状态,在等待队列中 PROPAGATE -3 状态需要向后传播 //不公平锁的lock函数 static final class NonfairSync ex...
2018-11-23 21:23:00 71
转载 wait()和notify()
package concurrent._wait_notify; public class Demo1 { public static void main(String[] args) throws InterruptedException { ThreadA a = new ThreadA("A"); synchronized (...
2018-11-23 14:30:00 73
转载 ReentrantLock的使用
package concurrent._ReentrantLock; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; //一个关于Lock的最基本操作,lock.lock()与lock.unlock() public class MyRee...
2018-11-23 11:03:00 87
转载 生产者消费者模式ArrayBlockingQueue
package concurrent._interrupt; import java.math.BigInteger; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class Demo3 { ...
2018-11-22 11:06:00 90
转载 interrupt
一个检查isinterrupted的程序 package concurrent._interrupt; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; public class Demo2 { private static int c ...
2018-11-22 10:07:00 94
转载 join()
代码: package concurrent._join; public class Demo { public static void main(String[] args) throws InterruptedException { ThreadA threadA = new ThreadA(); ThreadB thread...
2018-11-22 09:13:00 72
转载 LongAdder
add操作 public void add(long x) { Cell[] as; long b, v; int m; Cell a; //想要add一个元素的时候,先看一下cells数组是否为空,如果是空的就尝试去看能不能直接加到base上面,如果线程竞争很小就加到base上面了,函数结束 //如果cells是空的,...
2018-11-20 20:52:00 177
转载 ConcurrentHashMap源码
putval源码 final V putVal(K key, V value, boolean onlyIfAbsent) { //判断参数是否合格 if (key == null || value == null) throw new NullPointerException(); int hash = spread(k...
2018-11-17 18:50:00 78
转载 HashMap源码
putval方法 final V putVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict) { Node<K,V>[] tab; Node<K,V> p; int n, i; //查看是否是第一次p...
2018-11-17 10:04:00 75
转载 MapReduce单表关联
数据:找出孩子的爷爷奶奶姥姥老爷 child parentTom LucyTom JackJone LucyJone JackLucy MarryLucy JesseJack AliceJack JesseTerry AliceTerry JessePhilip TerryPhilip AlmaMark TerryMark Alma 结果: Jone Alic...
2018-11-08 18:12:00 158
转载 AtomicStampedReference
重要的参考博客: https://blog.csdn.net/zhaozhirongfree1111/article/details/72781758 package _AtomicStampedReference; import java.util.concurrent.atomic.AtomicMarkableReference; import java.uti...
2018-11-07 08:50:00 90
转载 SequenceFile
产生一个SequenceFile文件 package _SequenceFileInputFormat; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileSystem; ...
2018-11-05 19:12:00 59
转载 WordCount
1. 一个mapper package MapReduce; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException;...
2018-11-05 16:10:00 58
转载 IntUnaryOperator
将函数,变为,参数传入 1. 是一个接口,就是将一个对int类型的操作当一个参数传入进来。 关键函数:applyAsInt(int operand) 对一个参数operand进行一些操作,最后返回个int类型。 package _4; import java.util.function.IntUnaryOperator; public class MyI...
2018-11-03 09:15:00 623
转载 java复制
一个基本类: package ddemo; public class A { private String str; private int count; public A(String str,int count){ this.str = str; this.count = count; } ...
2018-11-02 10:37:00 77
转载 代理模式
1. 反射机制 标准: package _1._Agent.Reflect._DynamicLoading; public interface OfficeAble { void start(); } 标准实现: package _1._Agent.Reflect._DynamicLoading; public class Word ...
2018-11-02 08:42:00 54
转载 文件相关API
package HDFS; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org.apache.hadoop.io.IOUtils; import java.io.FileInputStream; import java.io.FileOutput...
2018-10-25 10:40:00 87
转载 阻塞队列-生产者与消费者模式
public class PC { public static void main(String[] args) { BlockingQueue<Integer> bq = new ArrayBlockingQueue<Integer>(5); for(int i = 0 ;i < 4 ; i +...
2018-10-22 16:20:00 68
转载 线程池2
ExecutorCompletionService有三个成员变量: executor:执行task的线程池,创建CompletionService必须指定; aes:主要用于创建待执行task; completionQueue:存储已完成状态的task,默认是基于链表结构的阻塞队列LinkedBlockingQueue。 ...
2018-10-20 15:50:00 65
转载 线程池1
任务类: package com._ThreadPool; public class MyTask implements Runnable { private int taskId; public MyTask(int id){ this.taskId = id; } @Override public voi...
2018-10-20 14:53:00 55
转载 一个高速的结果缓存
public interface Computable<A,V> { V compute(A arg) throws InterruptedException; } 实现一个计算接口 package com._resultCache; import java.math.BigInteger; /** * 一个很花费时间的计算 * ...
2018-10-18 15:21:00 64
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人