-
Notifications
You must be signed in to change notification settings - Fork 6
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
[barray] adopt the barray module #38
Open
ghost
wants to merge
11
commits into
reasonml-old:master
Choose a base branch
from
unknown repository
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
Show all changes
11 commits
Select commit
Hold shift + click to select a range
37fa965
[barray] adopt the barray module
dorafmon 0b65167
[barray] continue refactoring
dorafmon a1304be
[barray] add unit tests
dorafmon d9360c5
[barray] add unit tests
dorafmon a0f6caa
[barray] toSequence test
dorafmon 7cd7757
[barry] fix CI
dorafmon f858aa5
[barray] per review
dorafmon 2fb7eb7
[barray] per review
dorafmon 53a38c8
[barray] change format a little bit
dorafmon 9f26f25
[barray] format change and sequence refactor
dorafmon ba284d3
[barray] reformat
dorafmon 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# -*- conf -*- | ||
# This is an example configuration file for ocp-indent | ||
# | ||
# Copy to the root of your project with name ".ocp-indent", customise, and | ||
# transparently get consistent indentation on all your ocaml source files. | ||
|
||
# Starting the configuration file with a preset ensures you won't fallback to | ||
# definitions from "~/.ocp/ocp-indent.conf". | ||
# These are `normal`, `apprentice` and `JaneStreet` and set different defaults. | ||
normal | ||
|
||
# | ||
# INDENTATION VALUES | ||
# | ||
|
||
# Number of spaces used in all base cases, for example: | ||
# let foo = | ||
# ^^bar | ||
base = 2 | ||
|
||
# Indent for type definitions: | ||
# type t = | ||
# ^^int | ||
type = 4 | ||
|
||
# Indent after `let in` (unless followed by another `let`): | ||
# let foo = () in | ||
# ^^bar | ||
in = 0 | ||
|
||
# Indent after `match/try with` or `function`: | ||
# match foo with | ||
# ^^| _ -> bar | ||
with = 0 | ||
|
||
# Indent for clauses inside a pattern-match (after the arrow): | ||
# match foo with | ||
# | _ -> | ||
# ^^^^bar | ||
# the default is 2, which aligns the pattern and the expression | ||
match_clause = 4 # this is non-default | ||
|
||
# Indentation for items inside extension nodes: | ||
# [%% id.id | ||
# ^^^^contents ] | ||
# [@@id | ||
# ^^^^foo | ||
# ] | ||
ppx_stritem_ext = 2 | ||
|
||
# When nesting expressions on the same line, their indentation are in | ||
# some cases stacked, so that it remains correct if you close them one | ||
# at a line. This may lead to large indents in complex code though, so | ||
# this parameter can be used to set a maximum value. Note that it only | ||
# affects indentation after function arrows and opening parens at end | ||
# of line. | ||
# | ||
# for example (left: `none`; right: `4`) | ||
# let f = g (h (i (fun x -> # let f = g (h (i (fun x -> | ||
# x) # x) | ||
# ) # ) | ||
# ) # ) | ||
max_indent = 4 | ||
|
||
|
||
# | ||
# INDENTATION TOGGLES | ||
# | ||
|
||
# Wether the `with` parameter should be applied even when in a sub-block. | ||
# Can be `always`, `never` or `auto`. | ||
# if `always`, there are no exceptions | ||
# if `auto`, the `with` parameter is superseded when seen fit (most of the time, | ||
# but not after `begin match` for example) | ||
# if `never`, `with` is only applied if the match block starts a line. | ||
# | ||
# For example, the following is not indented if set to `always`: | ||
# let f = function | ||
# ^^| Foo -> bar | ||
strict_with = never | ||
|
||
# Controls indentation after the `else` keyword. `always` indents after the | ||
# `else` keyword normally, like after `then`. | ||
# If set to `never', the `else` keyword won't indent when followed by a newline. | ||
# `auto` indents after `else` unless in a few "unclosable" cases (`let in`, | ||
# `match`...). | ||
# | ||
# For example, with `strict_else=never`: | ||
# if cond then | ||
# foo | ||
# else | ||
# bar; | ||
# baz | ||
# `never` is discouraged if you may encounter code like this example, | ||
# because it hides the scoping error (`baz` is always executed) | ||
strict_else = always | ||
|
||
# Ocp-indent will normally try to preserve your in-comment indentation, as long | ||
# as it respects the left-margin or starts with `(*\n`. Setting this to `true` | ||
# forces alignment within comments. | ||
strict_comments = false | ||
|
||
# Toggles preference of column-alignment over line indentation for most | ||
# of the common operators and after mid-line opening parentheses. | ||
# | ||
# for example (left: `false'; right: `true') | ||
# let f x = x # let f x = x | ||
# + y # + y | ||
align_ops = true | ||
|
||
# Function parameters are normally indented one level from the line containing | ||
# the function. This option can be used to have them align relative to the | ||
# column of the function body instead. | ||
# if set to `always`, always align below the function | ||
# if `auto`, only do that when seen fit (mainly, after arrows) | ||
# if `never`, no alignment whatsoever | ||
# | ||
# for example (left: `never`; right: `always or `auto) | ||
# match foo with # match foo with | ||
# | _ -> some_fun # | _ -> some_fun | ||
# ^^parameter # ^^parameter | ||
align_params = auto | ||
|
||
|
||
# | ||
# SYNTAX EXTENSIONS | ||
# | ||
|
||
# You can also add syntax extensions (as per the --syntax command-line option): | ||
# syntax = mll lwt |
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,78 @@ | ||
open Perf | ||
|
||
let bigArray = Barray.makeWithInit 1_000_000 (fun _ -> Random.int 1024) | ||
let bigSeq = Barray.toSequence bigArray | ||
|
||
let toList = Array.to_list | ||
|
||
let fromList = Array.of_list | ||
|
||
let bigList = toList bigArray | ||
|
||
let fromSequenceArrayPush i = | ||
let open Bsequence in | ||
let arr = ref [||] in | ||
let rec aux i = | ||
match i () with | ||
| Nil -> !arr | ||
| Cons(x, r) -> ignore @@ Js.Array.push x !arr; aux r | ||
in aux i | ||
|
||
let listToSequence (l: 'a list) : 'a Bsequence.t = | ||
let rec aux ll () = match ll with | ||
| [] -> Bsequence.Nil | ||
| (e::r) -> Bsequence.Cons(e, aux (r)) | ||
in aux l | ||
|
||
let getSeqLength (s:'a Bsequence.t) : int = | ||
let open Bsequence in | ||
let rec aux i ss = | ||
match ss () with | ||
| Nil -> i | ||
| Cons (_, r) -> aux (i+1) r | ||
in aux 0 s | ||
|
||
let getFirstFromSeq (s:'a Bsequence.t) : 'a option = | ||
match s () with | ||
| Bsequence.Nil -> None | ||
| Bsequence.Cons (x, _) -> Some x | ||
|
||
let fromSequencePreAllocArray (s:'a Bsequence.t) :'a Barray.t = | ||
let len = getSeqLength s in | ||
let first = getFirstFromSeq s in | ||
match first with | ||
| None -> [||] | ||
| Some f -> begin | ||
let arr = ref (Barray.make len f) in | ||
let rec aux idx ss = | ||
match ss () with | ||
| Bsequence.Nil -> !arr | ||
| Bsequence.Cons (x, r) -> (!arr).(idx) <- x; aux (idx+1) r | ||
in aux 0 s | ||
end | ||
|
||
(** Do some correctness test first *) | ||
let _ = | ||
let lst = [1; 2; 3; 4] in | ||
let arr0 = fromList lst in | ||
let arr1 = fromSequenceArrayPush (listToSequence [1; 2; 3; 4]) in | ||
let arr2 = fromSequencePreAllocArray (listToSequence [1; 2; 3; 4]) in | ||
Js.log arr0; | ||
Js.log arr1; | ||
Js.log arr2 | ||
|
||
let _ = | ||
runPerfTest "listToArray - fromList" ~repeatTimes:100 (fun _ -> | ||
ignore @@ fromList bigList | ||
); | ||
runPerfTest "listToArray - fromSequence" ~repeatTimes:100 (fun _ -> | ||
ignore @@ fromSequenceArrayPush (listToSequence bigList) | ||
); | ||
let listSeq = listToSequence bigList in | ||
runPerfTest "listToArray - fromSequence - predefined seq" ~repeatTimes:100 (fun _ -> | ||
ignore @@ fromSequenceArrayPush listSeq | ||
); | ||
runPerfTest "listToArray - fromSequence - preallocated array" ~repeatTimes: 100 (fun _ -> | ||
ignore @@ fromSequencePreAllocArray (listToSequence bigList) | ||
) | ||
|
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,15 @@ | ||
open Perf | ||
|
||
let it = Barray.toSequence [| 1; 2 ; 3|] | ||
|
||
let _ = | ||
runPerfTest "Barray.toSequence" (fun _ -> | ||
ignore @@ ([| 1; 2; 3|] |> Barray.toSequence) | ||
); | ||
runPerfTest "Sequence.map" (fun _ -> | ||
ignore @@ Bsequence.map (fun x -> x * x) it | ||
); | ||
runPerfTest "Sequence.foldLeft" (fun _ -> | ||
Bsequence.reduce (fun acc x -> x::acc) [] it | ||
) | ||
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. These have actually gotten worse... Not sure why that would be |
||
|
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 doesn't look very good.
Either
or
or perhaps using
begin
/end
instead of parens would be better