Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
9267248b
Commit
9267248b
authored
9 years ago
by
Manos Koukoutos
Committed by
Ravi
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Type cardinality
parent
97f973e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/purescala/TypeOps.scala
+27
-0
27 additions, 0 deletions
src/main/scala/leon/purescala/TypeOps.scala
with
27 additions
and
0 deletions
src/main/scala/leon/purescala/TypeOps.scala
+
27
−
0
View file @
9267248b
...
@@ -249,4 +249,31 @@ object TypeOps extends GenTreeOps[TypeTree] {
...
@@ -249,4 +249,31 @@ object TypeOps extends GenTreeOps[TypeTree] {
transformer
.
transform
(
e
)(
ids
)
transformer
.
transform
(
e
)(
ids
)
}
}
}
}
def
typeCardinality
(
tp
:
TypeTree
)
:
Option
[
Int
]
=
tp
match
{
case
Untyped
=>
Some
(
0
)
case
BooleanType
=>
Some
(
2
)
case
UnitType
=>
Some
(
1
)
case
SetType
(
base
)
=>
typeCardinality
(
base
).
map
(
b
=>
Math
.
pow
(
2
,
b
).
toInt
)
case
FunctionType
(
from
,
to
)
=>
val
t
=
typeCardinality
(
to
).
getOrElse
(
return
None
)
val
f
=
from
.
map
(
typeCardinality
).
map
(
_
.
getOrElse
(
return
None
)).
product
Some
(
Math
.
pow
(
t
,
f
).
toInt
)
case
MapType
(
from
,
to
)
=>
for
{
t
<-
typeCardinality
(
to
)
f
<-
typeCardinality
(
from
)
}
yield
{
Math
.
pow
(
t
+
1
,
f
).
toInt
}
case
cct
:
CaseClassType
=>
Some
(
cct
.
fields
.
map
{
field
=>
typeCardinality
(
field
.
getType
).
getOrElse
(
return
None
)
}.
product
)
case
act
:
AbstractClassType
=>
Some
(
act
.
knownCCDescendants
.
map
(
typeCardinality
).
map
(
_
.
getOrElse
(
return
None
)).
sum
)
case
_
=>
None
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment