diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-09-12 14:16:22 +0000 |
---|---|---|
committer | <> | 2014-10-24 11:04:40 +0000 |
commit | a77e3a63f004e6ee789fa05e4a5bbc333b1529f1 (patch) | |
tree | efe8a68996c19b7b0765ebc689937721d1d99cf7 /ftok_experiment.py | |
download | sysv-ipc-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_python-packages_sysv-ipc-tarball/sysv_ipc-0.6.8.tar.gz.HEADsysv_ipc-0.6.8master
Diffstat (limited to 'ftok_experiment.py')
-rw-r--r-- | ftok_experiment.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ftok_experiment.py b/ftok_experiment.py new file mode 100644 index 0000000..95fcd21 --- /dev/null +++ b/ftok_experiment.py @@ -0,0 +1,50 @@ +"""This is an experiment to see how often ftok() returns duplicate keys for +different filenames. +""" + + +import sys +import os +import sysv_ipc + +if len(sys.argv) == 2: + start_path = sys.argv[1] +else: + msg = "Start path? [Default = your home directory] " + start_path = raw_input(msg) + if not start_path: + start_path = "~" + +# Expand paths that start with a tilde and then absolutize. +start_path = os.path.expanduser(start_path) +start_path = os.path.abspath(start_path) + +# For every filename in the tree, generate a key and associate the filename +# with that key via a dictionary. +d = { } +nfilenames = 0 +for path, dirnames, filenames in os.walk(start_path): + for filename in filenames: + # Fully qualify the path + filename = os.path.join(path, filename) + + nfilenames += 1 + + #print "Processing %s..." % filename + + key = sysv_ipc.ftok(filename, 42, True) + + if key not in d: + d[key] = [ ] + + d[key].append(filename) + +# Print statistics, including files with non-unique keys. +ndups = 0 +for key in d: + if len(d[key]) > 1: + ndups += len(d[key]) + print key, d[key] + +print "Out of {0} unique filenames, I found {1} duplicate keys.".format(nfilenames, ndups) + |