Commit 5e74db0a authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

added hash function to quantity.Discrete and misc

parent f5b9d15b
......@@ -5,7 +5,7 @@ arguments
names cell;
dim = 1;
end
sizes = [];
sizes = 0;
for k = 1:length(names)
if isfield(optArg, names{k})
sizes(k) = size(optArg.(names{k}), dim);
......
function h = hash(data)
%HASH compute the hash for some data
% h = hash(DATA) computes the SHA-1 hash for DATA
B = getByteStreamFromArray(data);
Engine = java.security.MessageDigest.getInstance('SHA-1');
Engine.update(B);
h = reshape( dec2hex(typecast(Engine.digest(), 'uint8')), 1, []);
end
......@@ -22,7 +22,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
properties ( Dependent )
% Name of the domains that generate the grid.
gridName {mustBe.unique};
......@@ -239,6 +239,22 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
methods (Access = public)
function h = hash(obj)
%HASH create a SHA-1 hash value for this object
% h = hash(obj) will copmute the SHA-1 hash value based on the
% data "valueDiscrete", "domain.name", "domain.grid",
% "obj.name"
% The hash value can be used to get a "short" identifier for
% this object.
% create a huge array of all relevant quantity data
data = {[ obj.valueDiscrete ], obj(1).domain.name, ...
obj(1).domain.grid, obj(1).name};
h = misc.hash(data);
end
function d = compositionDomain(obj, domainName)
assert(isscalar(obj));
......
......@@ -13,6 +13,19 @@ testCase.TestData.sym.t = t;
testCase.TestData.sym.sy = sy;
end
function testHashData(testCase)
spatialDomain = quantity.Domain("z", linspace(0, 1, 101));
L1 = quantity.Symbolic(diag([2, -3]), ...
'domain', spatialDomain, 'name', 'Lambda');
L2 = quantity.Symbolic(diag([1, -1]), ...
'domain', spatialDomain, 'name', 'Lambda');
testCase.verifyNotEqual(L1.hash, L2.hash);
end
function testIsdiag(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment