1 classdef MapExtended<containers.Map
3 function [isPos,reportStr]=isEqualProp(
self,otherObj)
4 isPos=isequal(
self.KeyType,otherObj.KeyType);
6 reportStr=
'incompatible key types';
8 isPos=
self.Count==0||otherObj.Count==0||...
9 isequal(
self.ValueType,otherObj.ValueType);
11 reportStr=
'incompatible value types';
18 function checkIfEqualProp(
self,otherObj)
20 [isPos,reportStr]=isEqualProp(
self,otherObj);
26 self=
self@containers.Map(varargin{:});
29 function obj=getUnionWith(
self,otherObj)
32 if self.Count>0||otherObj.Count>0
33 self.checkIfEqualProp(otherObj);
34 keyList=[
self.keys,otherObj.keys];
37 'key lists of both map objects cannot intersect');
41 [
self.values,otherObj.values]);
47 function SRes=toStruct(
self)
50 fieldNameList=cellfun(@
MapExtended.key2FieldName,keyList,...
51 'UniformOutput',false);
53 valueList=self.values;
54 isMapVec=cellfun('isclass',valueList,mfilename('class'));
55 valueList(isMapVec)=cellfun(@(x)x.toStruct(),...
56 valueList(isMapVec),'UniformOutput',false);
57 keyValueMat=[fieldNameList;valueList];
59 SRes=struct(keyValueMat{:});
62 function obj=getCopy(
self)
63 import
mxberry.core.cont.MapExtended;
65 isUniform=~strcmp(self.ValueType,'any');
66 obj=MapExtended(self.keys,self.values,'UniformValues',...
69 obj=MapExtended('KeyType',self.KeyType,...
70 'ValueType',self.ValueType);
73 function [isPos,reportStr]=isEqual(self,otherObj)
75 isPos=isequal(self,otherObj);
79 [isPos,reportStr]=self.isEqualProp(otherObj);
88 function fieldName=key2FieldName(keyName)
89 import
mxberry.core.cont.MapExtended;
90 N_MAX_NO_HASHED_CHARS=30;
92 nChars=length(keyName);
93 nNoHachedChars=min(N_MAX_NO_HASHED_CHARS,nChars);
94 fieldReadableNamePart=MapExtended.genVarName(...
95 keyName(1:nNoHachedChars));
96 nReadableChars=length(fieldReadableNamePart);
97 nNotHashed=min(nNoHachedChars,nReadableChars);
98 toHashStr=[fieldReadableNamePart(...
100 keyName(nNoHachedChars+1:end)];
102 if ~isempty(toHashStr)
103 if length(toHashStr)>32||~isvarname(toHashStr)
108 fieldName=[fieldReadableNamePart(1:nNotHashed),...
111 fieldName=fieldReadableNamePart(1:nNotHashed);
116 methods (Static, Access=private)
117 function varname=genVarName(varname)
118 if ~isvarname(varname) % Short-circuit if varname already legal
119 % Insert x if the first column is non-letter.
120 varname = regexprep(varname,'^\s*+([^A-Za-z])','x$1', 'once');
122 % Replace whitespace with camel casing.
123 [~, afterSpace] = regexp(varname,'\S\s+\S');
125 varname(j) = upper(varname(j));
127 varname = regexprep(varname,'\s+','');
128 if (isempty(varname))
131 % Replace non-word character with its HEXADECIMAL equivalent
132 illegalChars =
unique(varname(regexp(varname,'[^A-Za-z_0-9]')));
133 for illegalChar=illegalChars
134 if illegalChar <= intmax('uint8')
139 replace = ['0x' dec2hex(illegalChar,width)];
140 varname = strrep(varname, illegalChar, replace);
142 % Prepend keyword with 'x' and camel case.
143 if iskeyword(varname)
144 varname = ['x' upper(varname(1)) varname(2:end)];
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function hash(in inpArr, in methodName)
OBJECTHASH counts the hash of input object/array.
function unique(in inpVec)
UNIQUE for arrays of any type.
function structcompare(in SX, in SY, in absTol, in relTol)
STRUCTCOMPARE compares two structures using the specified tolerance.