Add build scripts for C# and

unify the coding style.
This commit is contained in:
krahets
2023-02-08 22:18:02 +08:00
parent 38751cc5f5
commit 6dc21691ed
63 changed files with 2703 additions and 3911 deletions
+3 -54
View File
@@ -513,60 +513,9 @@ $$
=== "C#"
```csharp title="array_hash_map.cs"
/* 键值对 int->String */
class Entry
{
public int key;
public String val;
public Entry(int key, String val)
{
this.key = key;
this.val = val;
}
}
/* 基于数组简易实现的哈希表 */
class ArrayHashMap
{
private List<Entry?> bucket;
public ArrayHashMap()
{
// 初始化一个长度为 100 的桶(数组)
bucket = new ();
for (int i = 0; i < 100; i++)
{
bucket.Add(null);
}
}
/* 哈希函数 */
private int hashFunc(int key)
{
int index = key % 100;
return index;
}
/* 查询操作 */
public String? get(int key)
{
int index = hashFunc(key);
Entry? pair = bucket[index];
if (pair == null) return null;
return pair.val;
}
/* 添加操作 */
public void put(int key, String val)
{
Entry pair = new Entry(key, val);
int index = hashFunc(key);
bucket[index]=pair;
}
/* 删除操作 */
public void remove(int key)
{
int index = hashFunc(key);
// 置为 null ,代表删除
bucket[index]=null;
}
}
[class]{Entry}-[func]{}
[class]{ArrayHashMap}-[func]{}
```
=== "Swift"