This file contains hidden or 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.Comparator; | |
import java.util.List; | |
public class SlowSort { | |
public static <T extends Comparable<? super T>> void slowSort(T[] array) { | |
slowSort(array, 0, array.length); | |
} | |
public static <T> void slowSort(T[] array, Comparator<? super T> comparator) { |
This file contains hidden or 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 re | |
from ply import lex, yacc | |
from ply.lex import TOKEN | |
import pyparsing as pp | |
# First, let's define a pyparsing parser for JSON. | |
class JSONPyParsing(object): | |
# pylint: disable-msg=W0104,E0213 |
This file contains hidden or 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
""" | |
Sample JSON decoder for demonstrating how to use pyparsing. | |
""" | |
import pyparsing as pp | |
# JSON types are number, string, boolean, object, array, and null. | |
# A boolean is either the literal 'true' or the literal 'false'. Set a | |
# parsing action that just replaces it with the Python equivalent. | |
boolean = ( |
This file contains hidden or 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
''' | |
Boyer-Moore exact string search, implemented from the description | |
given in: | |
http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/bmen.htm | |
''' | |
def _bad_character_shift(pat): | |
''' Calculates the bad character shift as the distance of the |
This file contains hidden or 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
''' | |
Created on 2011-10-09 | |
Modified Python Recipe: http://code.activestate.com/recipes/522995/ | |
@author: mavc | |
''' | |
from heapq import heapify, heappop, heappush | |
__all__ = ['PriorityDict'] |
NewerOlder