1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/test_bloom/generate_sets.py

39 lines
901 B
Python
Executable File

#!/usr/bin/env python2
import gzip
import random
import sys
sizeOfA = 10 * 1000
sizeOfB = 20
print sys.argv
if len(sys.argv) == 3:
sizeOfA = int(sys.argv[1])
sizeOfB = int(sys.argv[2])
# read all words
lines = [line.strip() for line in gzip.open('words.txt.gz')]
# get A lines
A = random.sample(lines, sizeOfA + sizeOfB)
# get B from the first sieOfB element
B = A[:sizeOfB]
A = A[sizeOfB:]
SetsFile = open('sets.h', 'w')
SetsFile.write('const int lenA = ' + str(sizeOfA) + ';\n')
SetsFile.write('const char* A[' + str(sizeOfA) + '] = {')
SetsFile.writelines(",".join('"' + x + '"\n' for x in A))
SetsFile.write('};\n')
SetsFile.write('const int lenB = ' + str(sizeOfB) + ';\n')
SetsFile.write('const char* B[' + str(sizeOfB) + '] = {')
SetsFile.writelines(",".join('"' + x + '"\n' for x in B))
SetsFile.write('};\n')
print("sets.h: sizeOfA = " + str(len(A) + len(B)) + " generated...")