So for the last step in implementing our hash table. Your
goal is to define a procedure, we'll call it hashtable_update. It takes
three inputs the hash table, the key, and the value. And
what it should do is update the value associated with that key.
So if the key is already in the table, then instead
of creating a new entry like were doing before with add. What
we want to do is change the value associated with that key,
to be the new value that's passed in. If it's not already
in the table, then what we want to do is
add a new entry, that has that key associated
with this value. This is going to be a pretty
complicated procedure. I think it's the most complex procedure you've
been asked to define so far. But if you
think about it carefully and put together all the things
we've seen so far, and understand how the hash-table
works, I think you'll be able to define it yourself.
ハッシュテーブルの実装の最終ステップです
目標は関数を定義することで
それをhashtable_updateと呼び
ハッシュテーブル、キー、そして値を入力します
行うべきことはそのキーに関連する値を
アップデートすることです
すでにテーブル内にキーがある場合
addメソッドを使用して以前行っていたように
新しいエントリを作成するのではなく
そのキーに関連する値を
新たに渡した値に変更するようにしたいのです
その値がテーブルにない場合に行うべきことは
値に関連したキーの
新しいエントリを追加することです
これはとても複雑な関数です
これまでに定義を求められたものの中で
一番複雑な関数だと思います
ですが学習したことをすべて合わせて慎重に考え
ハッシュテーブルを機能を理解すれば
自分で定義できるでしょう