This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn Y [f] | |
(#(% %) | |
(fn [x] #(apply (f (x x)) %&)))) | |
(def fib-gen | |
(fn [f] | |
(fn [n] | |
(if (= 0 n) 1 (* n (f (dec n))))))) | |
((Y fib-gen) 5) ;; => 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.nio.ByteBuffer; | |
import java.nio.channels.SelectionKey; | |
import java.nio.channels.Selector; | |
import java.nio.channels.ServerSocketChannel; | |
import java.nio.channels.SocketChannel; | |
import java.util.Objects; | |
import java.util.Set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
public class LRUCache { | |
private class Node { | |
Node prev, next; | |
int key, value; | |
Node (int key, int value) { | |
this.key = key; | |
this.value = value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.LinkedBlockingDeque; | |
/** | |
* java线程池 | |
* v1: 使用同步list 保存任务,synchronized wait notify实现任务分发 | |
* v2: 使用BlockingQueue 保存任务及任务分发 | |
* v3*: 前两种方式使用定时轮询检查flag来退出线程,v3 使用向任务队列尾部添加修改flag的任务的方式 | |
* Created by Ezio on 6/17/2016. | |
*/ |