Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clean-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
17
Issues
17
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
clean-and-itasks
clean-platform
Commits
99e10562
Commit
99e10562
authored
May 21, 2019
by
Steffen Michels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some code/efficiency improvements for IntMap
parent
c037c12b
Pipeline
#23451
passed with stage
in 3 minutes and 52 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
21 deletions
+17
-21
src/libraries/OS-Independent/Data/IntMap/Base.icl
src/libraries/OS-Independent/Data/IntMap/Base.icl
+17
-21
No files found.
src/libraries/OS-Independent/Data/IntMap/Base.icl
View file @
99e10562
...
...
@@ -492,14 +492,14 @@ alter f k t =
// > unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
// > == fromList [(3, "B3"), (5, "A3"), (7, "C")]
unions
::
![
IntMap
a
]
->
IntMap
a
unions
xs
=
foldl
Strict
union
empty
xs
unions
xs
=
foldl
union
empty
xs
// | The union of a list of maps, with a combining operation.
//
// > unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
// > == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")]
unionsWith
::
(
a
a
->
a
)
[
IntMap
a
]
->
IntMap
a
unionsWith
f
ts
=
foldl
Strict
(
unionWith
f
)
empty
ts
unionsWith
f
ts
=
foldl
(
unionWith
f
)
empty
ts
// | /O(n+m)/. The (left-biased) union of two maps.
// It prefers the first map when duplicate keys are encountered,
...
...
@@ -1226,7 +1226,7 @@ foldr` f z t =
//
// > let f len a = len + (length a)
// > foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
foldl
::
(
a
b
->
a
)
a
(
IntMap
b
)
->
a
/*
foldl :: (a b -> a) a (IntMap b) -> a
foldl f z t =
case t of Bin _ m l r | m < 0 -> go (go z r) l // put negative numbers before
| otherwise -> go (go z l) r
...
...
@@ -1234,7 +1234,7 @@ foldl f z t =
where
go z` Nil = z`
go z` (Tip _ x) = f z` x
go
z`
(
Bin
_
_
l
r
)
=
go
(
go
z`
l
)
r
go z` (Bin _ _ l r) = go (go z` l) r
*/
// | /O(n)/. A strict version of 'foldl'. Each application of the operator is
// evaluated before using the result in the next application. This
...
...
@@ -1426,7 +1426,7 @@ toDescList m = foldlWithKey (\xs k x -> [(k,x):xs]) [] m
// > fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
fromList
::
[(
Int
,
a
)]
->
IntMap
a
fromList
xs
=
foldl
Strict
ins
empty
xs
=
foldl
ins
empty
xs
where
ins
t
(
k
,
x
)
=
insert
k
x
t
...
...
@@ -1445,7 +1445,7 @@ fromListWith f xs
//// > fromListWithKey f [] == empty
fromListWithKey
::
(
Int
a
a
->
a
)
[(
Int
,
a
)]
->
IntMap
a
fromListWithKey
f
xs
=
foldl
Strict
ins
empty
xs
=
foldl
ins
empty
xs
where
ins
t
(
k
,
x
)
=
insertWithKey
f
k
x
t
...
...
@@ -1492,10 +1492,11 @@ fromDistinctAscList :: ![(!Int, !a)] -> IntMap a
fromDistinctAscList
[]
=
Nil
fromDistinctAscList
[
z0
:
zs0
]
=
work
z0
zs0
Nada
where
work
::
!(!
Int
,
!
a
)
![(!
Int
,
!
a
)]
!(
Stack
a
)
->
IntMap
a
work
(
kx
,
vx
)
[]
stk
=
finish
kx
(
Tip
kx
vx
)
stk
work
(
kx
,
vx
)
[
z
=:(
kz
,_):
zs
]
stk
=
reduce
z
zs
(
branchMask
kx
kz
)
kx
(
Tip
kx
vx
)
stk
reduce
::
(
Int
,
a
)
[(
Int
,
a
)]
Mask
Prefix
(
IntMap
a
)
(
Stack
a
)
->
IntMap
a
reduce
::
!(!
Int
,
!
a
)
![(!
Int
,
!
a
)]
!
Mask
!
Prefix
!(
IntMap
a
)
!
(
Stack
a
)
->
IntMap
a
reduce
z
zs
_
px
tx
Nada
=
work
z
zs
(
Push
px
tx
Nada
)
reduce
z
zs
m
px
tx
stk
=:(
Push
py
ty
stk`
)
=
let
mxy
=
branchMask
px
py
...
...
@@ -1504,6 +1505,7 @@ fromDistinctAscList [z0 : zs0] = work z0 zs0 Nada
(
reduce
z
zs
m
pxy
(
Bin
pxy
mxy
ty
tx
)
stk`
)
(
work
z
zs
(
Push
px
tx
stk
))
finish
::
!
Prefix
!(
IntMap
a
)
!(
Stack
a
)
->
IntMap
a
finish
_
t
Nada
=
t
finish
px
tx
(
Push
py
ty
stk
)
=
finish
p
(
link
py
ty
px
tx
)
stk
where
m
=
branchMask
px
py
...
...
@@ -1571,17 +1573,11 @@ branchMask :: !Prefix !Prefix -> Mask
branchMask
p1
p2
=
highestBitMask
(
p1
bitxor
p2
)
highestBitMask
::
!
Int
->
Int
highestBitMask
x0
=
case
(
x0
bitor
(
x0
>>
1
))
of
x1
->
case
(
x1
bitor
(
x1
>>
2
))
of
x2
->
case
(
x2
bitor
(
x2
>>
4
))
of
x3
->
case
(
x3
bitor
(
x3
>>
8
))
of
x4
->
case
(
x4
bitor
(
x4
>>
16
))
of
x5
->
case
(
x5
bitor
(
x5
>>
32
))
of
// for 64 bit platforms
x6
->
(
x6
bitxor
(
x6
>>
1
))
foldlStrict
::
!(
a
b
->
a
)
!
a
![
b
]
->
a
foldlStrict
f
acc
[]
=
acc
foldlStrict
f
acc
[
x
:
xs
]
#!
z`
=
f
acc
x
=
foldlStrict
f
z`
xs
highestBitMask
x0
=
x6
bitxor
(
x6
>>
1
)
where
x1
=
x0
bitor
(
x0
>>
1
)
x2
=
x1
bitor
(
x1
>>
2
)
x3
=
x2
bitor
(
x2
>>
4
)
x4
=
x3
bitor
(
x3
>>
8
)
x5
=
x4
bitor
(
x4
>>
16
)
x6
=
x5
bitor
(
x5
>>
32
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment