By Forrest Green (2010)
493626
def si_prefix(value):
    
    #standard si prefixes
    prefixes = ['y','z','a','f','p','n','u','m','','k','M','G','T','P','E','Z','Y']

    from math import log
    #closest 1000 exponent
    if value == 0: return (value, "")
    exp = int(log(value,1000)//1) + 8
    if exp < 0: exp = 0
    if exp > 16: exp = 16
    return (value*1000**(-(exp-8)), prefixes[exp])
327748
function (aColumnsIds, bVisibilityValue) {
			var aColumns = this.treeTable.getColumns();

			aColumns.forEach(function(oColumn) {
				oColumn.setVisible(!bVisibilityValue);
				aColumnsIds.forEach(function(sRuleId) {
					if (oColumn.sId.includes(sRuleId)) {
						oColumn.setVisible(bVisibilityValue);
					}
				});
			});
		}
316935
private static int[] getRGBs(IndexColorModel pColorModel) {
        int[] rgb = new int[pColorModel.getMapSize()];
        pColorModel.getRGBs(rgb);

        return rgb;
    }
244546
private boolean computeScore(Sentence sentence, SmartForest<Double> forest, boolean offset) {
		SmartGetWord<Double> sgw = new SmartGetWord<Double>(forest, sentence.value.toLowerCase());
		String name = null;
		boolean flag = false;
		while ((name = sgw.getFrontWords()) != null) {
			flag = true;
			sentence.updateScore(name, sgw.getParam());
			if (offset) {
				Triplet<Integer, Integer, Double> triplet = new Triplet<Integer, Integer, Double>(sgw.offe, sgw.offe+name.length(), sgw.getParam());
				sentence.offset.add(triplet);
			}
		}
		if (sentence.score == 0) {
			sentence.score = sentence.value.length() * -0.005;
		} else {
			sentence.score /= Math.log(sentence.value.length() + 3);
		}

		return flag;
	}
1199228
def green_callback(fn, obj=None, green_mode=None):
    """"""
    executor = get_object_executor(obj, green_mode)

    @wraps(fn)
    def greener(*args, **kwargs):
        return executor.submit(fn, *args, **kwargs)

    return greener
1039778
def greenhall_sw(t, alpha):
    
    alpha = int(alpha)
    if alpha == 2:
            return -np.abs(t)
    elif alpha == 1:
        if t == 0:
            return 0
        else:
            return pow(t, 2)*np.log(np.abs(t))
    elif alpha == 0:
        return np.abs(pow(t, 3))
    elif alpha == -1:
        if t == 0:
            return 0
        else:
            return pow(t, 4)*np.log(np.abs(t))
    elif alpha == -2:
        return np.abs(pow(t, 5))
    elif alpha == -3:
        if t == 0:
            return 0
        else:
            return pow(t, 6)*np.log(np.abs(t))
    elif alpha == -4:
        return np.abs(pow(t, 7))

    assert(0)
108064
private View openIndex(int flags, boolean dryRun) throws ForestException {
        if (_view == null) {
            // Flags:
            if (_dbStore.getAutoCompact())
                flags |= Database.AutoCompact;

            // Encryption:
            SymmetricKey encryptionKey = _dbStore.getEncryptionKey();
            int enAlgorithm = Database.NoEncryption;
            byte[] enKey = null;
            if (encryptionKey != null) {
                enAlgorithm = Database.AES256Encryption;
                enKey = encryptionKey.getKey();
            }

            _view = new View(_dbStore.forest, _path, flags, enAlgorithm, enKey, name,
                    dryRun ? "0" : delegate.getMapVersion());
            if (dryRun) {
                closeIndex();
            }
        }
        return _view;
    }
884561
private void gc() {

        I_CmsLruCacheObject currentObject = m_listTail;
        while (currentObject != null) {
            if (m_objectCosts < m_avgCacheCosts) {
                break;
            }
            currentObject = currentObject.getNextLruObject();
            removeTail();
        }
    }
1264017
private void buildNode(Node parent, List<String>[] sequence, int from, List<Node> leaf){
        //递归退出条件：二维数组遍历完毕
        if(from >= sequence.length){
            //记住叶子节点
            leaf.add(parent);
            return;
        }
        for(String item : sequence[from]){
            Node child = new Node(item, parent);
            buildNode(child, sequence, from+item.length(), leaf);
        }
    }
1318117
def etree(A):
    
    assert isinstance(A,spmatrix), "A must be a sparse matrix"
    assert A.size[0] == A.size[1], "A must be a square matrix"

    n = A.size[0]
    cp,ri,_ = A.CCS
    parent = matrix(0,(n,1))
    w = matrix(0,(n,1))

    for k in range(n):
        parent[k] = k
        w[k] = -1
        for p in range(cp[k],cp[k+1]):
            i = ri[p]
            while ((not i == -1) and (i < k)):
                inext = w[i]
                w[i] = k
                if inext == -1: parent[i] = k
                i = inext;

    return parent
1196226
void initIRGB(int[] pTemp) {
        final int x = (1 << TRUNCBITS);        // 8 the size of 1 Dimension of each quantized cell
        final int xsqr = 1 << (TRUNCBITS * 2); // 64 - twice the smallest step size vale of quantized colors
        final int xsqr2 = xsqr + xsqr;

        for (int i = 0; i < numColors; ++i) {
            if (i == transparentIndex) {
                // Skip the transparent pixel
                continue;
            }

            int red, r, rdist, rinc, rxx;
            int green, g, gdist, ginc, gxx;
            int blue, b, bdist, binc, bxx;

            // HaraldK 20040801: Added support for int[]
            if (rgbMapByte != null) {
                red = rgbMapByte[i * 4] & 0xFF;
                green = rgbMapByte[i * 4 + 1] & 0xFF;
                blue = rgbMapByte[i * 4 + 2] & 0xFF;
            }
            else if (rgbMapInt != null) {
                red = (rgbMapInt[i] >> 16) & 0xFF;
                green = (rgbMapInt[i] >> 8) & 0xFF;
                blue = rgbMapInt[i] & 0xFF;
            }
            else {
                throw new IllegalStateException("colormap == null");
            }

            rdist = red - x / 2;   // distance of red to center of current cell
            gdist = green - x / 2; // green
            bdist = blue - x / 2;  // blue
            rdist = rdist * rdist + gdist * gdist + bdist * bdist;

            rinc = 2 * (xsqr - (red << TRUNCBITS));
            ginc = 2 * (xsqr - (green << TRUNCBITS));
            binc = 2 * (xsqr - (blue << TRUNCBITS));

            int rgbI = 0;
            for (r = 0, rxx = rinc; r < MAXQUANTVAL; rdist += rxx, ++r, rxx += xsqr2) {
                for (g = 0, gdist = rdist, gxx = ginc; g < MAXQUANTVAL; gdist += gxx, ++g, gxx += xsqr2) {
                    for (b = 0, bdist = gdist, bxx = binc; b < MAXQUANTVAL; bdist += bxx, ++b, ++rgbI, bxx += xsqr2) {
                        if (i == 0 || pTemp[rgbI] > bdist) {
                            pTemp[rgbI] = bdist;
                            inverseRGB[rgbI] = (byte) i;
                        }
                    }
                }
            }
        }
    }
180411
def bggreen(cls, string, auto=False):
        
        return cls.colorize('bggreen', string, auto=auto)
571382
private void bfs(int v, int[] cc, int id) {
        cc[v] = id;
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(v);
        while (!queue.isEmpty()) {
            int t = queue.poll();
            for (Edge edge : graph[t]) {
                int i = edge.v2;
                if (!digraph && i == t) {
                    i = edge.v1;
                }

                if (cc[i] == -1) {
                    queue.offer(i);
                    cc[i] = id;
                }
            }
        }
    }
329125
@Override
    public int getIndexForColor(int rgb) {
        int red = (rgb >> 16) & 0xff;
        int green = (rgb >> 8) & 0xff;
        int blue = rgb & 0xff;

        OctTreeNode node = root;

        for (int level = 0; level <= MAX_LEVEL; level++) {
            OctTreeNode child;
            int bit = 0x80 >> level;

            int index = 0;
            if ((red & bit) != 0)
                index += 4;
            if ((green & bit) != 0)
                index += 2;
            if ((blue & bit) != 0)
                index += 1;

            child = node.leaf[index];

            if (child == null)
                return node.index;
            else if (child.isLeaf)
                return child.index;
            else
                node = child;
        }
        LOGGER.fine("getIndexForColor failed");
        return 0;
    }
1126947
private Viterbi<PersonNode> getPersonNodeViterbi(Term[] terms) {
        Term first;
        PersonNatureAttr fPna;
        Term second;
        Term third;
        Term from;
        for (int i = 0; i < terms.length - 1; i++) {
            first = terms[i];

            if (first == null) {
                continue;
            }

            fPna = getPersonNature(first);
            setNode(first, A);

            if (fPna.getY() > 0) {
                setNode(first, Y);
            }

            if (!fPna.isActive()) {
                continue;
            }

            second = first.to();
            if (second.getOffe() == terms.length || second.getName().length() > 2) { //说明到结尾了,或者后面长度不符合规则
                continue;
            }

            third = second.to();
            from = first.from();


            //XD
            if (first.getName().length() == 2) {
                setNode(from, K);
                setNode(from, M);
                setNode(first, X);
                setNode(second, D);
                setNode(third, M);
                setNode(third, L);
                continue;
            }

            setNode(from, K);
            setNode(from, M);
            setNode(first, B);
            setNode(third, M);
            setNode(third, L);
            //BZ
            if (second.getName().length() == 2) {
                setNode(second, Z);
                continue;
            } else {//BE
                setNode(second, E);
            }


            if (third.getOffe() == terms.length || third.getName().length() > 1) { //说明到结尾了,或者后面长度不符合规则
                continue;
            }

            //BCD
            setNode(first, B);
            setNode(second, C);
            setNode(third, D);
            setNode(third.to(), M);
            setNode(third.to(), L);

        }
        PersonNatureAttr begin = DATDictionary.person("BEGIN");

        nodes[0][6] = null;
        nodes[0][4] = new PersonNode(4, "B", -Math.log(begin.getK()));
        nodes[0][10] = new PersonNode(10, "B", -Math.log(begin.getA()));

        PersonNatureAttr end = DATDictionary.person("END");
        nodes[terms.length][5] = new PersonNode(5, "E", -Math.log(end.getL()));
        nodes[terms.length][6] = null;
        nodes[terms.length][10] = new PersonNode(10, "E", -Math.log(end.getA()));

        return new Viterbi<PersonNode>(nodes, new Values<PersonNode>() {
            @Override
            public int step(Node<PersonNode> node) {
                return node.getObj().name.length();
            }

            @Override
            public double selfSscore(Node<PersonNode> node) {
                return node.getObj().score;
            }

        });
    }
1074887
private void bfs(int v, int[] cc, int id) {
        cc[v] = id;
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(v);
        while (!queue.isEmpty()) {
            int t = queue.poll();
            for (int i = 0; i < n; i++) {
                if (graph[t][i] != 0.0 && cc[i] == -1) {
                    queue.offer(i);
                    cc[i] = id;
                }
            }
        }
    }
561948
function spfa(graph, s) {
  const distance = {};
  const previous = {};
  const queue = {};
  const isInQue = {};
  const cnt = {};
  let head = 0;
  let tail = 1;
  // initialize
  distance[s] = 0;
  queue[0] = s;
  isInQue[s] = true;
  cnt[s] = 1;
  graph.vertices.forEach(v => {
    if (v !== s) {
      distance[v] = Infinity;
      isInQue[v] = false;
      cnt[v] = 0;
    }
  });

  let currNode;
  while (head !== tail) {
    currNode = queue[head++];
    isInQue[currNode] = false;
    const neighbors = graph.neighbors(currNode);
    for (let i = 0; i < neighbors.length; i++) {
      const v = neighbors[i];
      // relaxation
      const newDistance = distance[currNode] + graph.edge(currNode, v);
      if (newDistance < distance[v]) {
        distance[v] = newDistance;
        previous[v] = currNode;
        if (!isInQue[v]) {
          queue[tail++] = v;
          isInQue[v] = true;
          cnt[v]++;
          if (cnt[v] > graph.vertices.size) {
            // indicates negative-weighted cycle
            return {
              distance: {}
            };
          }
        }
      }
    }
  }

  return {
    distance,
    previous
  };
}