Mercurial > octave
changeset 23358:42bd10feedfa
use new hex2num and num2hex features to simplify +containers.Map key encoding
* +containers/Map.m (encode_keys): Simplify with new num2hex features.
(decode_keys): Simplify with new hex2num features.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Apr 2017 15:06:42 -0400 |
parents | 426b593b4b6b |
children | dd6ce1e09a4c |
files | scripts/+containers/Map.m |
diffstat | 1 files changed, 3 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/+containers/Map.m Thu Apr 06 14:52:38 2017 -0400 +++ b/scripts/+containers/Map.m Thu Apr 06 15:06:42 2017 -0400 @@ -479,39 +479,16 @@ keys = cell2mat (keys); endif endif - ## FIXME: Replace with csprintf when it becomes available. - ## Use explicit width in format to ensure that we print all digits - ## even when there are leading zeros. - if (any (strcmp (this.KeyType, {"single", "int32", "uint32"}))) - keytype = "uint32"; - fmt = "%0.8X|"; - else - keytype = "uint64"; - fmt = "%0.16X|"; - endif - keys = ostrsplit (sprintf (fmt, typecast (keys, keytype)), "|", true); + keys = num2hex (keys); if (! cell_input) keys = char (keys); endif - endfunction function keys = decode_keys (this, keys) if (this.numeric_keys) - ## Since we typecast the key to uint32 or uint64 before - ## converting to hex, it would probably be better if hex2num - ## could return uint32 or uint64 directly, then we could - ## typecast back to other types. - if (any (strcmp (this.KeyType, {"single", "int32", "uint32"}))) - keytype = "single"; - else - keytype = "double"; - endif - keys = hex2num (keys, keytype); - if (! strcmp (this.KeyType, keytype)) - keys = typecast (keys, this.KeyType); - endif - keys = mat2cell (keys.', 1, ones (numel (keys), 1)); + keys = hex2num (keys, this.KeyType); + keys = mat2cell (keys(:)', 1, ones (numel (keys), 1)); endif endfunction