Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nirmalathasa_comp30023_2019_project-2
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
Abhisha Nirmalathas
nirmalathasa_comp30023_2019_project-2
Commits
d1576130
Commit
d1576130
authored
6 years ago
by
Abhisha Nirmalathas
Browse files
Options
Downloads
Patches
Plain Diff
remove vals from hsh table
parent
9b1e8183
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hashtable.c
+11
-0
11 additions, 0 deletions
hashtable.c
hashtable.h
+3
-0
3 additions, 0 deletions
hashtable.h
with
14 additions
and
0 deletions
hashtable.c
+
11
−
0
View file @
d1576130
...
...
@@ -22,6 +22,7 @@ struct bucket {
struct
table
{
int
size
;
//number of buckets
Bucket
*
buckets
;
//list of buckets
int
remaining
;
};
/************************************************************************/
...
...
@@ -72,6 +73,7 @@ HashTable *new_hash_table(int size) {
assert
(
table
);
table
->
size
=
size
;
table
->
buckets
=
malloc
(
size
*
(
sizeof
*
table
->
buckets
));
table
->
remaining
=
size
;
assert
(
table
->
buckets
);
int
i
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
...
...
@@ -150,7 +152,9 @@ int hash_table_get(HashTable *table, char *key) {
for
(
int
i
=
0
;
i
<
bucket
->
n_elems
;
i
++
){
if
(
equal
(
bucket
->
keys
[
i
],
key
)){
freq
=
bucket
->
values
[
i
];
bucket
->
keys
[
i
]
=
""
;
move_to_front
(
bucket
,
i
);
table
->
remaining
--
;
break
;
}
}
...
...
@@ -169,8 +173,15 @@ bool hash_table_has(HashTable *table, char *key) {
Bucket
*
bucket
=
&
table
->
buckets
[
hash_value
];
for
(
int
i
=
0
;
i
<
bucket
->
n_elems
;
i
++
){
if
(
equal
(
bucket
->
keys
[
i
],
key
)){
// reset hash to avoid duplicate keys
bucket
->
keys
[
i
]
=
""
;
table
->
remaining
--
;
return
true
;
}
}
return
false
;
}
/************************************************************************/
int
remaining_hashes
(
HashTable
*
table
){
return
table
->
remaining
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hashtable.h
+
3
−
0
View file @
d1576130
...
...
@@ -22,3 +22,6 @@ int hash_table_get(HashTable *table, char *key);
//Checks if the key exists in hash table
bool
hash_table_has
(
HashTable
*
table
,
char
*
key
);
// Returns the remaining values inside hashtable
int
remaining_hashes
(
HashTable
*
table
);
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