2009-06-13 1 views
0

私はハッシュツリーを使用するP2Pアプリケーションに取り組んでいます。アーランハッシュツリー

私はハッシュツリー構築関数(publ/4とpubl_top/4)を書いていますが、publ_top/4を修正する方法はわかりません。私はPUBL/1でツリーを構築しようとし

nivd:publ("file.txt"). 

prints hashes... 

** exception error: no match of right hand side value [67324168] 
    in function nivd:publ_top/4 
    in call from nivd:publ/1 

コードの問題ではここにある:

あなたは問題があると思います

http://github.com/AndreasBWagner/nivoa/blob/886c624c116c33cc821b15d371d1090d3658f961/nivd.erl

は、私はあなたが空のリストと照合する最初の関数宣言では、特定の例外エラー

publ_top(_,[],Accumulated,Level) -> 
    %% Go through the accumulated list of hashes from the prior level 
    publ_top(string:len(Accumulated),Accumulated,[],Level+1); 

publ_top(FullLevelLen,RestofLevel,Accumulated,Level) -> 
    case FullLevelLen =:= 1 of 
    false -> [F,S|T]=RestofLevel, 
     io:format("~w---~w~n",[F,S]), 
     publ_top(FullLevelLen,T,lists:append(Accumulated,[erlang:phash2(string:concat([F],[S]))]),Level); 
    true -> done 
    end. 

を生成する1つの問題を見ることができ、 アンドレアスあなたのコードを見てみると

+0

あなたは好奇心旺盛であれば、アプリがここで説明されています:のhttp://wiki.github

エラーは、おそらく何かのように、関数の引数に場合と同じパターンマッチを見つけるために容易になるだろう.com/AndreasBWagner/nivoa – andreasw

答えて

4

をありがとうございました。 2番目の宣言では、長さ(少なくとも)2([F,S|T])のリストと照合します。 FullLevelLenが1と異なり、RestOfLevelが長さ1のリストの場合はどうなりますか? (ヒント:上記のエラーが表示されます)。

publ_top(_,[],Accumulated,Level) -> 
    %% Go through the accumulated list of hashes from the prior level 
    publ_top(string:len(Accumulated),Accumulated,[],Level+1); 

publ_top(1, _, _, _) -> 
    done; 

publ_top(_, [F,S|T], Accumulated, Level) -> 
    io:format("~w---~w~n",[F,S]), 
    publ_top(FullLevelLen,T,lists:append(Accumulated,[erlang:phash2(string:concat([F],[S]))]),Level); 

%% Missing case: 
% publ_top(_, [H], Accumulated, Level) -> 
%  ... 
+0

ありがとう!プログラムはハッシュツリーを作成し、あなたのスタイルのヒントは私のコーディングを改善しました。 – andreasw