Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMtools/hash_lookup.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [val, found, Nentries] = hash_lookup(key, fname) | |
2 % HASH_LOOKUP Lookup a key in a hash table stored in a file using linear search | |
3 % function [val, found, Nentries] = hash_lookup(key, filename) | |
4 % | |
5 % Example: | |
6 % If htbl.mat does not exist, | |
7 % [val,found,N] = hash_lookup('foo', 'htbl') | |
8 % returns found val = [], found = 0, N = 0 | |
9 % hash_add('foo', 42, 'htbl') | |
10 % hash_add('bar', [1:10], 'htbl') | |
11 % [val,found,N] = hash_lookup('foo', 'htbl') | |
12 % now returns val = 42, found = 1, N = 2 | |
13 % | |
14 % Type 'delete htbl' to delete the file/ reset the hashtable | |
15 | |
16 | |
17 val = []; | |
18 found = 0; | |
19 | |
20 if exist(fname, 'file')==0 | |
21 % new hashtable | |
22 Nentries = 0; | |
23 else | |
24 %hashtable = importdata(fname); | |
25 load(fname); | |
26 Nentries = length(hashtable.key); | |
27 for i=1:Nentries | |
28 if isequal(hashtable.key{i}, key) | |
29 val = hashtable.value{i}; | |
30 found = 1; | |
31 break; | |
32 end | |
33 end | |
34 end |