摘要: 1 python lambda会创建一个函数对象,但不会把这个函数对象赋给一个标识符,而def则会把函数对象赋值给一个变量。2 python lambda它只是一个表达式,而def则是一个语句。下面是python lambda的格式,看起来好精简阿。lambda x: print x如果你在python 列表解析里用到python lambda,我感觉意义不是很大,因为python lambda它会创建一个函数对象,但马上又给丢弃了,因为你没有使用它的返回值,即那个函数对象。也正是由于lambda只是一个表达式,它可以直接作为python 列表或python 字典的成员,比如:info = [ 阅读全文
posted @ 2012-07-24 17:00 rilley 阅读(1042) 评论(0) 推荐(0) 编辑
摘要: map函数func作用于给定序列的每个元素,并用一个列表来提供返回值。map函数python实现代码:1 def map(func,seq):2 mapped_seq = []3 for eachItem in seq:4 mapped_seq.append(func(eachItem))5 return mapped_seq filter函数的功能相当于过滤器。调用一个布尔函数bool_func来迭代遍历每个seq中的元素;返回一个使bool_seq返回值为true的元素的序列。filter函数python代码实现:1 def filter(bool_... 阅读全文
posted @ 2012-07-24 16:48 rilley 阅读(223) 评论(0) 推荐(0) 编辑
摘要: VM运行时数据区域JVM执行Java程序的过程中,会使用到各种数据区域,这些区域有各自的用途、创建和销毁时间。根据《Java虚拟机规范(第二版)》(下文称VM Spec)的规定,JVM包括下列几个运行时数据区域:------------------------------------------------------------------------------------------------------------------------- 1.程序计数器(Program Counter Register): 每一个Java线程都有一个程序计数器来用于保存程序执行到当前方法的哪一个指 阅读全文
posted @ 2012-07-16 17:24 rilley 阅读(1045) 评论(0) 推荐(0) 编辑
摘要: 1 public abstract class SelectableChannel extends AbstractChannel implements Channel 2 { 3 public abstract void configureBlocking (boolean block) throws IOException; 4 public abstract boolean isBlocking( ); 5 public abstract Object blockingLock( ); 6 } 7 8 public abstract class... 阅读全文
posted @ 2012-07-16 17:21 rilley 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 运算符 ~ 按位非(NOT)(一元运算) & 按位与(AND) | 按位或(OR) ^ 按位异或(XOR) >> 右移 >>> 右移,左边空出的位以0填充 << 左移 &= 按位与赋值 |= 按位或赋值 ^= 按位异或赋值 >>= 右移赋值 >>>= 右移赋值,左边空出的位以0填充 <<= 左移赋值优先级 1 ()[] 2 ++(后缀) --(后缀) 3 ++(前缀) --(前缀) +(正) -(负) ! ~ instanceof 4 New(类型) 5 * / % 6 +(加) -(减) 7 阅读全文
posted @ 2012-07-16 17:00 rilley 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 1 import java.util.Random; 2 3 4 public class RBTree 5 { 6 7 private Node root; 8 9 10 public RBTree(int[] array) 11 { 12 for (int i : array) insert(i); 13 } 14 15 private Node search(int key, Node node) 16 { 17 if (node == nul... 阅读全文
posted @ 2012-07-11 18:47 rilley 阅读(253) 评论(1) 推荐(0) 编辑
摘要: 原帖地址 http://www.iteye.com/topic/561590 1 import java.util.Collection; 2 import java.util.Iterator; 3 import java.util.NoSuchElementException; 4 5 public class BinarySearchTree<E extends Comparable<E>> 6 { 7 8 public static void main(String[] args) 9 { 10 BinarySearchT... 阅读全文
posted @ 2012-07-11 15:39 rilley 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 1 public class FibHeap 2 { 3 private FibNode min; 4 5 private int count; 6 7 private FibNode root; 8 9 10 public FibHeap() 11 { 12 root = new FibNode(); 13 root.left = root; 14 root.right = root; 15 } 16 17 /* 18 ... 阅读全文
posted @ 2012-07-11 15:36 rilley 阅读(643) 评论(1) 推荐(0) 编辑
摘要: 1 public class BinaryHeap<E extends Comparable<? super E>> 2 { 3 4 public static void main(String[] args) 5 { 6 Integer[] array = {0, 12, 90, 1, 85, 12, 3, 13, 49, 7 55, 10, 3, 31, 97, 19, 93, 41, 55, 56, 82, 2}; 8 9 BinaryHeap<Integer> he... 阅读全文
posted @ 2012-07-10 15:55 rilley 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 1 public class DisjoinSet 2 { 3 4 public static void main(String[] args) 5 { 6 DisjoinSet disjoin = new DisjoinSet(8); 7 8 disjoin.union(4, 3); 9 disjoin.union(5, 4);10 disjoin.union(6, 5);11 disjoin.union(7, 6);12 disjoin.union(8, 7);13 ... 阅读全文
posted @ 2012-07-10 15:54 rilley 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 插入排序 1 public static void insertSort(Comparable[] array) 2 { 3 int j = 0; 4 5 for (int i = 1; i < array.length; i++) { 6 Comparable temp = array[i]; 7 8 for (j = i; j > 0 && (temp.compareTo(array[j - 1]) < 0); j--) { 9 ... 阅读全文
posted @ 2012-07-02 16:06 rilley 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 1 public class BinarySearch 2 { 3 4 public static int search(int[] array, int n) 5 { 6 int low = 0, mid = 0; 7 int high = array.length - 1; 8 9 while (low <= high) {10 11 mid = (low + high) >> 1;12 13 if (arr... 阅读全文
posted @ 2012-03-21 22:41 rilley 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 1 public class ArrayDeque<E> 2 { 3 4 private static final int MIN_INITIAL_CAPACITY = 16; 5 6 private E[] elements; 7 8 private int head; 9 10 private int tail; 11 12 13 public ArrayDeque() 14 { 15 elements = (E[]) new Object[MIN_IN... 阅读全文
posted @ 2012-03-21 15:59 rilley 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 添加节点1.修改host 和普通的datanode一样。添加namenode的ip2.修改namenode的配置文件conf/slaves 添加新增节点的ip或host3.在新节点的机器上,启动服务[root@slave-004 hadoop]# ./bin/hadoop-daemon.sh start datanode[root@slave-004 hadoop]# ./bin/hadoop-daemon.sh start tasktracker 4.均衡block[root@slave-004 hadoop]# ./bin/start-balancer.sh1)如果不balance,那么. 阅读全文
posted @ 2012-02-13 18:33 rilley 阅读(14060) 评论(3) 推荐(4) 编辑
摘要: package java.util.concurrent;import java.util.concurrent.locks.*;import java.util.*;public class ThreadPoolExecutor extends AbstractExecutorService { /** * runState provides the main lifecyle control, taking on values: * * RUNNING: Accept new tasks and process queued tasks * ... 阅读全文
posted @ 2012-02-07 17:47 rilley 阅读(2425) 评论(2) 推荐(1) 编辑