上一页 1 2 3 4 5 6 7 ··· 10 下一页

Graph and Tree in Python

摘要: Adjacency Lists and the LikeOne of the most intuitive ways of implementing graphs is using adjacency lists. Basically, for each node, we can access a list (or set or other container or iterable) of its neighbors.a, b, c, d, e, f, g, h = range(8) N = [ {b, c, d, e, f}, # a {c, e}, # b {d}, ... 阅读全文
posted @ 2012-08-15 14:14 grep 阅读(326) 评论(0) 推荐(0) 编辑

OO in python

摘要: self,instance variable,instance method,class variable, class variable""" circle module."""class Circle: """Circle class""" all_circles = [] pi = 3.14159 def __init__(self,r=1): self.radius = r self.__class__.all_circles.append(self) def are 阅读全文
posted @ 2012-08-14 16:10 grep 阅读(218) 评论(0) 推荐(0) 编辑

python function

摘要: Because the arguments to power in the final invocation of it are named, their order is irrelevant; the arguments are associated with the parameters of the same name in the definition is called key-word passing.Keyword passing, in combination with the default argument capability of Python functions, 阅读全文
posted @ 2012-08-13 10:59 grep 阅读(773) 评论(0) 推荐(0) 编辑

list and dictionary comprehension

摘要: You can think of a list or dictionary comprehension as aone-line for loop that creates a new list or dictionary from another list. The pattern ofa list comprehension is as follows:new_list = [expression for variable in old_list if expression]new_dict = {expression:expression for variable in list if 阅读全文
posted @ 2012-08-07 16:28 grep 阅读(195) 评论(0) 推荐(0) 编辑

matrix in python

摘要: A fairly standard way to represent such a matrix is by means of a list of lists. like this.matrix = [[3, 0, -2, 11], [0, 9, 0, 0], [0, 7, 0, 0], [0, 0, 0, -5]]then access byelement = matrix[rownum][colnum]but for sparse matrices.It's simple to implement sparse matrices using dictionaries with tu 阅读全文
posted @ 2012-08-07 15:59 grep 阅读(3476) 评论(0) 推荐(0) 编辑

how tomcat works revisited

摘要: code// check if this is a request for a servlet or// a static resource// a request for a servlet begins with "/servlet/"if (request.getUri().startsWith("/servlet/")) {ServletProcessor1 processor = new ServletProcessor1();processor.process(request, response);}else {StaticResourePr 阅读全文
posted @ 2012-07-16 09:31 grep 阅读(176) 评论(0) 推荐(0) 编辑

Enum

摘要: abstractpublic enum Operation {PLUS("+") {double apply(double x, double y) { return x + y; }},MINUS("-") {double apply(double x, double y) { return x - y; }},TIMES("*") {double apply(double x, double y) { return x * y; }},DIVIDE("/") {double apply(double x, do 阅读全文
posted @ 2012-07-15 19:43 grep 阅读(222) 评论(0) 推荐(0) 编辑

customize synchronizers

摘要: Structure of Blocking State-dependent actionsvoid blockingAction() throws InterruptedException { acquire lock on object state while (precondition does not hold) { release lock wait until precondition might hold optionally fail if interrupted or timeout expires reacq... 阅读全文
posted @ 2012-07-15 19:14 grep 阅读(221) 评论(0) 推荐(0) 编辑

design pattern reloaded

摘要: Singletonpublic final class Singleton{private static Singleton INSTANCE = new Singleton();private Singleton(){}public static Singleton instance(){return INSTANCE;}public Object read(){//nasty database call}}test :(public class TestVictim{public void testSomething(){//holy crap, how do I mock the dat 阅读全文
posted @ 2012-07-15 14:56 grep 阅读(160) 评论(0) 推荐(0) 编辑

Java Language Inside-Out

摘要: FAQpass-by-value vs pass-by-referencewhat is dominator tree?Solutions:1Pass-by-valuePass-by-referenceThe actual parameter is fully evaluated and the resulting value is copied into a location(typically, on stack)The formal parameter merely acts as an alias for the acutal parameterpublic void foo(Dog 阅读全文
posted @ 2012-07-13 21:17 grep 阅读(194) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 10 下一页