-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C# docs for PersistentHashMap - references #2
- Loading branch information
Showing
8 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PersistentHashMap | ||
================ | ||
|
||
A Map is a collection that maps keys to values. Hash maps require keys that correctly support GetHashCode and Equals. Hash maps provide fast access (log32N hops). Count is O(1). | ||
|
||
[lang=csharp,file=csharp/PersistentHashMap.cs,key=create-hashmap] | ||
|
||
PersistentHashMaps are immutable and therefor allow to create new version without destruction of the old ones. | ||
|
||
[lang=csharp,file=csharp/PersistentHashMap.cs,key=modify-hashmap] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using FSharpx.Collections; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace CSharp | ||
{ | ||
class PersistentHashMapSamples | ||
{ | ||
public static void Samples([CallerFilePath] string file = "") | ||
{ | ||
// ------------------------------------------------------------ | ||
// Creating PersistentVectors | ||
// ------------------------------------------------------------ | ||
|
||
// [create-hashmap] | ||
// Create an empty PersistentHashMap and add some elements | ||
PersistentHashMap<int,string> map = | ||
PersistentHashMap<int, string>.Empty() | ||
.Add(42,"hello") | ||
.Add(99, "world"); | ||
|
||
Console.WriteLine(map[42]); // hello | ||
Console.WriteLine(map[99]); // world | ||
|
||
// Check no. of elements in the PersistentHashMap | ||
Console.WriteLine(map.Length); // 2 | ||
|
||
// [/create-hashmap] | ||
|
||
// [modify-hashmap] | ||
PersistentHashMap<int, string> map2 = | ||
map | ||
.Add(104, "!") | ||
.Add(42, "hi"); // replace existing value | ||
|
||
Console.WriteLine(map2[42]); // hi | ||
Console.WriteLine(map[42]); // hello | ||
|
||
Console.WriteLine(map.Length); // 2 | ||
Console.WriteLine(map2.Length); // 3 | ||
|
||
// remove the last element from a PersistentHashMap | ||
PersistentHashMap<int, string> map3 = map2.Remove(104); | ||
|
||
Console.WriteLine(map3.Length); // 2 | ||
|
||
// [/modify-hashmap] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters