-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Bring over additional types from Onivim 2 #22
Open
bryphe
wants to merge
4
commits into
master
Choose a base branch
from
refactor/additional-onivim-types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@ | ||
module Key: { | ||
type t = | ||
pri { | ||
hash: int, | ||
name: string, | ||
}; | ||
let compare: (t, t) => int; | ||
let create: string => t; | ||
} = { | ||
type t = { | ||
hash: int, | ||
name: string, | ||
}; | ||
|
||
let compare = (a, b) => | ||
a.hash == b.hash ? compare(a.name, b.name) : compare(a.hash, b.hash); | ||
|
||
let create = name => {hash: Hashtbl.hash(name), name}; | ||
}; | ||
|
||
include Map.Make(Key); | ||
|
||
let key = Key.create; | ||
let keyName = (key: key) => key.name; |
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,39 @@ | ||
type key; | ||
let key: string => key; | ||
let keyName: key => string; | ||
|
||
type t(+'a); | ||
|
||
let empty: t('a); | ||
let is_empty: t('a) => bool; | ||
|
||
let mem: (key, t('a)) => bool; | ||
let add: (key, 'a, t('a)) => t('a); | ||
let update: (key, option('a) => option('a), t('a)) => t('a); | ||
let remove: (key, t('a)) => t('a); | ||
let merge: | ||
((key, option('a), option('b)) => option('c), t('a), t('b)) => t('c); | ||
let union: ((key, 'a, 'a) => option('a), t('a), t('a)) => t('a); | ||
|
||
let compare: (('a, 'a) => int, t('a), t('a)) => int; | ||
let equal: (('a, 'a) => bool, t('a), t('a)) => bool; | ||
|
||
let iter: ((key, 'a) => unit, t('a)) => unit; | ||
let fold: ((key, 'a, 'b) => 'b, t('a), 'b) => 'b; | ||
|
||
let for_all: ((key, 'a) => bool, t('a)) => bool; | ||
let exists: ((key, 'a) => bool, t('a)) => bool; | ||
|
||
let filter: ((key, 'a) => bool, t('a)) => t('a); | ||
let partition: ((key, 'a) => bool, t('a)) => (t('a), t('a)); | ||
|
||
let find_opt: (key, t('a)) => option('a); | ||
let find_first_opt: (key => bool, t('a)) => option((key, 'a)); | ||
let find_last_opt: (key => bool, t('a)) => option((key, 'a)); | ||
|
||
let map: ('a => 'b, t('a)) => t('b); | ||
let mapi: ((key, 'a) => 'b, t('a)) => t('b); | ||
|
||
let to_seq: t('a) => Seq.t((key, 'a)); | ||
let add_seq: (Seq.t((key, 'a)), t('a)) => t('a); | ||
let of_seq: Seq.t((key, 'a)) => t('a); |
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,4 @@ | ||
include KeyedTree.Make(String); | ||
|
||
let path = String.split_on_char('.'); | ||
let key = String.concat("."); |
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,4 @@ | ||
include KeyedTree.S with type key = string; | ||
|
||
let path: string => path; | ||
let key: path => string; |
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,179 @@ | ||
module type OrderedType = Map.OrderedType; | ||
|
||
module type S = { | ||
type key; | ||
type path = list(key); | ||
module KeyedMap: Map.S with type key := key; | ||
type t('a) = | ||
| Node(KeyedMap.t(t('a))) | ||
| Leaf('a); | ||
|
||
let empty: t(_); | ||
|
||
let fromList: list((path, 'a)) => t('a); | ||
|
||
let add: (path, 'a, t('a)) => t('a); | ||
let get: (path, t('a)) => option('a); | ||
|
||
let merge: | ||
((path, option('a), option('b)) => option('c), t('a), t('b)) => t('c); | ||
let union: ((path, 'a, 'a) => option('a), t('a), t('a)) => t('a); | ||
let map: ('a => 'b, t('a)) => t('b); | ||
let fold: ((path, 'a, 'b) => 'b, t('a), 'b) => 'b; | ||
}; | ||
|
||
module Make = (Ord: OrderedType) => { | ||
type key = Ord.t; | ||
type path = list(key); | ||
module KeyedMap = Map.Make(Ord); | ||
type t('a) = | ||
| Node(KeyedMap.t(t('a))) | ||
| Leaf('a); | ||
|
||
let empty = Node(KeyedMap.empty); | ||
|
||
let rec update = (path, value: option('a), node: t('a)) => { | ||
switch (path) { | ||
| [] => node | ||
|
||
| [key] => | ||
switch (node) { | ||
| Node(children) => | ||
Node( | ||
KeyedMap.update( | ||
key, | ||
fun | ||
| None => Option.map(value => Leaf(value), value) | ||
| Some(Leaf(_)) => Option.map(value => Leaf(value), value) // duplicate, override existing value | ||
| Some(Node(_)) as node => node, // ignore if internal node, NOTE: lossy | ||
children, | ||
), | ||
) | ||
| Leaf(_) => | ||
switch (value) { | ||
| Some(value) => Node(KeyedMap.singleton(key, Leaf(value))) | ||
| None => Node(KeyedMap.empty) | ||
} | ||
} | ||
|
||
| [key, ...rest] => | ||
switch (node) { | ||
| Node(children) => | ||
let newChildren = | ||
KeyedMap.update( | ||
key, | ||
fun | ||
| Some(Node(_) as child) => Some(update(rest, value, child)) | ||
| None | ||
| Some(Leaf(_)) => Some(update(rest, value, empty)), // override leaf, NOTE: lossy | ||
children, | ||
); | ||
|
||
Node(newChildren); | ||
|
||
| Leaf(_) => | ||
// override leaf, NOTE: lossy | ||
let child = update(rest, value, empty); | ||
Node(KeyedMap.singleton(key, child)); | ||
} | ||
}; | ||
}; | ||
|
||
let add = (keys, value) => update(keys, Some(value)); | ||
|
||
let fromList = entries => | ||
List.fold_left( | ||
(acc, (key, value)) => add(key, value, acc), | ||
empty, | ||
entries, | ||
); | ||
|
||
let rec get = (path, node) => | ||
switch (path, node) { | ||
| ([], Leaf(value)) => Some(value) | ||
| ([key, ...rest], Node(children)) => | ||
switch (KeyedMap.find_opt(key, children)) { | ||
| Some(child) => get(rest, child) | ||
| None => None | ||
} | ||
| _ => None | ||
}; | ||
|
||
let merge = (f, a, b) => { | ||
let f = (path, a, b) => | ||
Option.map(value => Leaf(value), f(path, a, b)); | ||
|
||
let rec aux = (path, a, b) => | ||
switch (a, b) { | ||
| (Leaf(a), Leaf(b)) => f(path, Some(a), Some(b)) | ||
| (Node(_), Leaf(b)) => f(path, None, Some(b)) | ||
| (Leaf(a), Node(_)) => f(path, Some(a), None) | ||
| (Node(aChildren), Node(bChildren)) => | ||
let merged = | ||
KeyedMap.merge( | ||
(key, a, b) => { | ||
let path = [key, ...path]; | ||
switch (a, b) { | ||
| (Some(a), Some(b)) => aux(path, a, b) | ||
| (None, Some(b)) => aux(path, empty, b) | ||
| (Some(a), None) => aux(path, a, empty) | ||
| (None, None) => failwith("unreachable") | ||
}; | ||
}, | ||
aChildren, | ||
bChildren, | ||
); | ||
|
||
if (merged == KeyedMap.empty) { | ||
None; | ||
} else { | ||
Some(Node(merged)); | ||
}; | ||
}; | ||
|
||
aux([], a, b) |> Option.value(~default=empty); | ||
}; | ||
|
||
let union = f => { | ||
let rec aux = (f, path, a, b) => | ||
switch (a, b) { | ||
| (Leaf(_), Leaf(b)) => Leaf(b) // duplicate, override a with b | ||
| (Node(_), Leaf(_)) => a // Node always wins, NOTE: lossy | ||
| (Leaf(_), Node(_)) => b // Node always wins, NOTE: lossy | ||
| (Node(aChildren), Node(bChildren)) => | ||
// merge children | ||
let merged = | ||
KeyedMap.union( | ||
(key, a, b) => { | ||
let path = [key, ...path]; | ||
Some(aux(f, path, a, b)); | ||
}, | ||
aChildren, | ||
bChildren, | ||
); | ||
Node(merged); | ||
}; | ||
|
||
aux(f, []); | ||
}; | ||
|
||
let rec map = f => | ||
fun | ||
| Leaf(value) => Leaf(f(value)) | ||
| Node(children) => Node(KeyedMap.map(map(f), children)); | ||
|
||
let fold = (f, node, initial) => { | ||
let rec traverse = (node, revPath, acc) => | ||
switch (node) { | ||
| Leaf(value) => f(List.rev(revPath), value, acc) | ||
| Node(children) => | ||
KeyedMap.fold( | ||
(key, node, acc) => traverse(node, [key, ...revPath], acc), | ||
children, | ||
acc, | ||
) | ||
}; | ||
|
||
traverse(node, [], initial); | ||
}; | ||
}; |
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,6 @@ | ||
(library | ||
(name Core) | ||
(public_name vscode-exthost.core) | ||
(library_flags (-linkall)) | ||
(libraries luv yojson decoders-yojson) | ||
(preprocess (pps ppx_deriving.show ppx_deriving_yojson))) | ||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this should have been removed entirely? |
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,25 @@ | ||
module type OrderedType = Map.OrderedType; | ||
|
||
module type S = { | ||
type key; | ||
type path = list(key); | ||
module KeyedMap: Map.S with type key := key; | ||
type t('a) = | ||
| Node(KeyedMap.t(t('a))) | ||
| Leaf('a); | ||
|
||
let empty: t(_); | ||
|
||
let fromList: list((path, 'a)) => t('a); | ||
|
||
let add: (path, 'a, t('a)) => t('a); | ||
let get: (path, t('a)) => option('a); | ||
|
||
let merge: | ||
((path, option('a), option('b)) => option('c), t('a), t('b)) => t('c); | ||
let union: ((path, 'a, 'a) => option('a), t('a), t('a)) => t('a); | ||
let map: ('a => 'b, t('a)) => t('b); | ||
let fold: ((path, 'a, 'b) => 'b, t('a), 'b) => 'b; | ||
}; | ||
|
||
module Make: (Ord: OrderedType) => S with type key = Ord.t; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, and the interface, seems to be duplicated in
Types
.