Comment créer et accéder à un dictionnaire (ou une carte ou une table de hachage) avec Octave? J'ai essayé plusieurs façons, mais il y a peut-être des moyens plus efficaces. Voici le code pour montrer ce que j'ai essayé. Il utilise des entrées de fichier .mat fournies ici: https://www.dropbox.com/s/4v1z1q04ivpgjvf/sample_input_dictionary.mat?dl=0Comment créer et accéder à un dictionnaire (ou une carte ou une table de hachage) avec Octave
% Methods to build/use a dictionary on Octave
clear
tic
load sample_input_dictionary.mat;
pkg load general
toc
% Dict-based dictionary, using the "general" package: very slow to access
d_dict = dict(nodes, num2cell(1:numel(nodes)));
toc
% Struct-based dictionary: slower to build, much faster to access
temp = [nodes', num2cell([1:numel(nodes)]')] .';
d_struct = struct(temp{:}); clear temp;
toc
% Is there an equivalent and more efficient cell-based dictionary?
% A different struct-based dictionary, which I could not build vectorially
t = struct();
for m=1:numel(nodes)
t.(nodes{m}) = edges{m};
end
toc
% Example of accessing the above dictionaries
d_dict('1234') % this takes forever
d_struct.('1234')
t.('1234')
S'il vous plaît montrer quelques code et ce que vous avez essayé jusqu'à présent, DEVENEZ MCVE https://stackoverflow.com/ help/mcve – Andy
Merci de m'avoir signalé. J'ai ajouté le code. – highalpha