Mercurial > hg > camir-ismir2012
comparison toolboxes/FullBNT-1.0.7/KPMtools/hash_lookup.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cc4b1211e677 |
---|---|
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 |