-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhash_table_2D.m
More file actions
69 lines (53 loc) · 1.89 KB
/
hash_table_2D.m
File metadata and controls
69 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [forwardHash,inverseHash] = hash_table_2D(Lev,Dim,gridType)
% [forwardHash,inverseHash] = HashTable(Lev,Dim,gridType)
%-------------------------------------------------
% Generate 2D Hash Table s.t n1+n2<=Lev
% Input: Lev:: Level information
% Dim:: Dimensionality
% Output: forwardHash:: HashTable
% inverseHash:: Inverse Looking up for Hash
% Major Change:: ignoring the Deg from mesh
% Adding the 1D index into HashTable with
% (Lev_1D,Cell_1D)->Index_1D
% so the inv = (Lev_1,Lev_2,Cell_1,Cell_2,Index_1,Index_2)
% key = [Lev_1,Lev_2,Cell_1,Cell_2]
%-------------------------------------------------
if ~exist('gridType','var') || isempty(gridType)
gridType = 'SG'; % Set default gridType to SG
end
% global hash_format
%
% % Specifies the number of allowable integers in the elements of the hash key
% % If more are needed, i.e., > 99, then change to 'i%3.3i_'.
%
% hash_format = 'i%04.4d';
%%
% Set the hash format in one place
set_hash_format
count=1;
forwardHash = struct(); % Empty struct array
inverseHash = {}; % Empty cell array
for n1=0:Lev
if strcmp(gridType,'FG')
Lev_tmp = Lev;
else
Lev_tmp = Lev-n1;
end
for n2=0:Lev_tmp
for i1=0:max(0,2^max(0,n1-1)-1)
for i2=0:max(0,2^max(0,n2-1)-1)
key=[n1,n2,i1,i2];
forwardHash.(sprintf(hash_format,key)) = count;
% Linearize the heirarchial multi-index for each dimension.
index_1 = lev_cell_to_1D_index(n1,i1);
index_2 = lev_cell_to_1D_index(n2,i2);
inverseHash{count} = [key,index_1,index_2];
count = count+1;
end
end
end
end
% Add some other useful information to the forwardHash struct
forwardHash.Lev = Lev;
forwardHash.Dim = Dim;
end