mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Beginning to implement Dict size
This commit is contained in:
parent
64d69b9ec4
commit
41c1fa06da
4 changed files with 19 additions and 4 deletions
|
@ -2,9 +2,8 @@ const std = @import("std");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const expectEqual = testing.expectEqual;
|
const expectEqual = testing.expectEqual;
|
||||||
|
|
||||||
|
|
||||||
const RocDict = struct {
|
const RocDict = struct {
|
||||||
len: u32,
|
size: usize,
|
||||||
|
|
||||||
pub fn init() RocDict {
|
pub fn init() RocDict {
|
||||||
return RocDict{
|
return RocDict{
|
||||||
|
@ -17,6 +16,9 @@ const RocDict = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn dictSize(dict: RocDict) usize {
|
||||||
|
return dict.size;
|
||||||
|
}
|
||||||
|
|
||||||
test "RocDict.init() contains nothing" {
|
test "RocDict.init() contains nothing" {
|
||||||
const dict = RocDict.init();
|
const dict = RocDict.init();
|
||||||
|
|
|
@ -2,6 +2,12 @@ const builtin = @import("builtin");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
|
// Dict Module
|
||||||
|
const dict = @import("dict.zig");
|
||||||
|
comptime {
|
||||||
|
exportDictFn(dict.size, "size");
|
||||||
|
}
|
||||||
|
|
||||||
// Num Module
|
// Num Module
|
||||||
const num = @import("num.zig");
|
const num = @import("num.zig");
|
||||||
comptime {
|
comptime {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
interface Dict2
|
interface Dict
|
||||||
exposes [ isEmpty, map ]
|
exposes [ isEmpty, map ]
|
||||||
imports []
|
imports []
|
||||||
|
|
||||||
|
size : Dict * * -> Nat
|
||||||
|
|
||||||
isEmpty : Dict * * -> Bool
|
isEmpty : Dict * * -> Bool
|
||||||
|
|
||||||
## Convert each key and value in the #Dict to something new, by calling a conversion
|
## Convert each key and value in the #Dict to something new, by calling a conversion
|
||||||
|
@ -13,4 +15,8 @@ isEmpty : Dict * * -> Bool
|
||||||
##
|
##
|
||||||
## `map` functions like this are common in Roc, and they all work similarly.
|
## `map` functions like this are common in Roc, and they all work similarly.
|
||||||
## See for example #Result.map, #List.map, and #Set.map.
|
## See for example #Result.map, #List.map, and #Set.map.
|
||||||
map : List before, (before -> after) -> List after
|
map :
|
||||||
|
Dict beforeKey beforeValue,
|
||||||
|
(\{ key: beforeKey, value: beforeValue } ->
|
||||||
|
{ key: afterKey, value: afterValue }
|
||||||
|
) -> Dict afterKey afterValue
|
||||||
|
|
|
@ -882,6 +882,7 @@ define_builtins! {
|
||||||
3 DICT_SINGLETON: "singleton"
|
3 DICT_SINGLETON: "singleton"
|
||||||
4 DICT_GET: "get"
|
4 DICT_GET: "get"
|
||||||
5 DICT_INSERT: "insert"
|
5 DICT_INSERT: "insert"
|
||||||
|
6 DICT_SIZE: "size"
|
||||||
}
|
}
|
||||||
7 SET: "Set" => {
|
7 SET: "Set" => {
|
||||||
0 SET_SET: "Set" imported // the Set.Set type alias
|
0 SET_SET: "Set" imported // the Set.Set type alias
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue