Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-orbit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Katerina Roukounaki
cloud-orbit
Commits
540e897d
Commit
540e897d
authored
Nov 13, 2014
by
Yiannis Tsiouris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add type for table of vertices
parent
bf5f7959
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
Table.hs
Table.hs
+6
-5
No files found.
Table.hs
View file @
540e897d
...
...
@@ -21,32 +21,33 @@ module Table( new
import
Data.Array
(
Array
,
elems
,
listArray
,
(
!
),
(
//
))
type
Freq
=
[
Int
]
type
VTable
=
Array
Int
[
Int
]
-- Note: Hash tables have a fixed number of slots but each slot can store
-- a list of vertices. The functions is_member/3 and insert/3
-- expect its slot argument to be in range.
-- new(Size) creates a table with Size slots, each containing an empty list.
new
::
Int
->
Array
Int
[
Int
]
new
::
Int
->
VTable
new
size
=
listArray
(
0
,
size
-
1
)
$
cycle
[
[]
]
-- to_list(T) converts a table T into a list of its entries.
to_list
::
Array
Int
[
Int
]
->
[
Int
]
to_list
::
VTable
->
[
Int
]
to_list
=
concat
.
elems
-- is_member(X, I, T) is true iff X is stored in table T at slot I.
is_member
::
Int
->
Int
->
Array
Int
[
Int
]
->
Bool
is_member
::
Int
->
Int
->
VTable
->
Bool
is_member
x
i
t
=
elem
x
(
t
!
i
)
-- insert(X, I, T) inserts X into table T at slot I.
insert
::
Int
->
Int
->
Array
Int
[
Int
]
->
Array
Int
[
Int
]
insert
::
Int
->
Int
->
VTable
->
VTable
insert
x
i
t
=
t
//
[(
i
,
x
:
t
!
i
)]
-- get_freq computes the fill frequency of table T;
-- the output is a list of integers where the number at position I
-- indicates how many slots of T are filled with I entries;
-- the sum of the output lists equals the number of slots of T.
get_freq
::
Array
Int
[
Int
]
->
Freq
get_freq
::
VTable
->
Freq
get_freq
t
=
elems
$
foldl
(
flip
inc
)
freqArr
freqs
where
freqs
=
map
length
$
elems
t
maxFreq
=
foldl
max
(
head
freqs
)
(
tail
freqs
)
...
...
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