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
#!/usr/bin/env python | |
import random | |
import sys | |
class node( object ): | |
""" a vertex | |
""" | |
def __init__( self, key ): | |
""" c'tor """ | |
self.key = key |
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
class Node( object ): | |
""" | |
.. class:: Node | |
rbTree Node | |
""" | |
def __init__( self, key ): | |
""" c'tor """ | |
self.left = None |
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
__bc16b = [ 0 ] * (256*256) | |
for i in range(256*256): | |
__bc16b[i] = ( i & 1 ) + __bc16b[i/2] | |
def popcnt16b( arg ): | |
""" popcnt using 16bits loom up table """ | |
return sum( [ __bc16b[( arg >> i ) & 65535 ] for i in range( 0, arg.bit_length(), 16 ) ] ) |
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
## bit count look up table in range 0..255 | |
__bcLUT = [ 0 ] * 256 | |
for i in range(256): | |
__bcLUT[i] = ( i & 1 ) + __bcLUT[i/2] | |
def popcntLUT( arg ): | |
""" popcnt using look up table """ | |
assert type(arg) in ( int, long ) | |
return sum( [ __bcLUT[ ( arg >> i ) & 255 ] | |
for i in range( 0, arg.bit_length(), 8 ) ] ) |
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
# --- testBK.py | |
import sys | |
import random | |
from popcnt import popcntBK | |
up = 2**256 | |
for i in range(1, 1001): | |
if not i % 10: | |
print ".", | |
sys.stdout.flush() | |
if not i % 100: |
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
#!/bin/env python | |
""" :mod: popcnt | |
============ | |
.. module: popcnt | |
:synopsis: couting bits set ("1") in int or long | |
.. moduleauthor:: Krzysztof.Ciba@NOSPAMgmail.com | |
""" | |
## bit count look up table in range 0..255 | |
__bcLUT = [ 0 ] * 256 |
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
#!/bin/env python | |
""" | |
Solves a problem of getting permutation of a given index, | |
while you know that permutations are created in a lexicographical order. | |
As input you are specifying a list of elements and index of permutation you want to get. | |
""" | |
## imports | |
from math import factorial | |
## this one just for checking |
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
from multiprocessing import Process, Manager | |
def sender( S ): | |
print "sending 256 MB" | |
S["foo"] = "."*256*1024*1024 | |
if __name__ == '__main__': | |
m = Manager() | |
S = m.dict() |
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
[Tue, 19 Feb 19:25 E1][cibak@localhost:~]> python pipeBuf.py | |
send 0 B | |
read 0 B | |
send 1024 B | |
read 1024 B | |
send 2048 B | |
read 2048 B | |
[...cut...] | |
read 59392 B | |
send 60416 B |
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
from multiprocessing import Pipe | |
if __name__ == "__main__": | |
( pout, pin ) = Pipe(False) | |
for i in range(1024): | |
pin.send("."*i*1024) | |
print "send", i*1024, "B" | |
r = pout.recv() | |
print "read", len(r), "B" |
NewerOlder