Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
key-value-store
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Samarth Joshi
key-value-store
Commits
4e04511c
Commit
4e04511c
authored
Nov 09, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.cse.iitb.ac.in/samarthjoshi/key-value-store
parents
20c2bcf6
3353b49b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
temp.c
temp.c
+21
-15
No files found.
temp.c
View file @
4e04511c
...
...
@@ -51,7 +51,7 @@ void file_del(off_t offset, char *key)
sem_post
(
&
mutex
[
index
]);
}
void
file_get
(
off_t
offset
,
char
*
key
,
char
*
value
)
void
file_get
(
char
*
key
,
char
*
value
)
{
/* Gets the value stored at offset */
/* Does not depend on key argument */
...
...
@@ -62,25 +62,24 @@ void file_get(off_t offset, char *key, char *value)
if
(
readCounters
[
index
]
==
1
)
sem_wait
(
&
mutex
[
index
]);
sem_post
(
&
readerLocks
[
index
]);
lseek
(
fds
[
index
],
offset
,
SEEK_SET
);
char
line
[
10
];
char
*
line
;
//FILE *fp =fdopen(fds[index],"r+");
// fseek(fp, offset,SEEK_SET);
size_t
len
=
0
;
char
ch
;
int
k
=-
1
;
while
(
read
(
fds
[
index
],
&
ch
,
sizeof
(
ch
))
!=-
1
&&
ch
!=
'\n'
)
{
if
(
k
>=
0
)
{
value
[
k
++
]
=
ch
;
}
if
(
ch
==
':'
)
{
k
=
0
;
FILE
*
fp
=
fdopen
(
fds
[
index
],
"r+"
);
while
((
getline
(
&
line
,
&
len
,
fp
))
!=
-
1
)
{
char
*
fkey
=
strtok
(
line
,
":"
)
;
char
*
fvalue
=
strtok
(
NULL
,
":"
);
if
(
strcmp
(
key
,
fkey
)
==
0
){
memcpy
(
value
,
fvalue
,
strlen
(
fvalue
));
break
;
}
}
sem_wait
(
&
readerLocks
[
index
]);
readCounters
[
index
]
-=
1
;
...
...
@@ -107,6 +106,13 @@ off_t file_put(char *key,char *value) {
sem_post
(
&
mutex
[
index
]);
return
position
;
}
void
file_search
(
char
*
key
,
char
*
value
)
{
int
index
=
modulus
(
key
,
256
,
setSize
);
}
int
main
()
{
...
...
@@ -146,8 +152,8 @@ int main()
offset
=
file_put
(
prevkey
,
"value1"
);
offset
=
file_put
(
key
,
value
);
file_get
(
9
,
prevkey
,
value
);
// Doesnot depend on key arg, returns key and value at offset 0
file_get
(
prevkey
,
value
);
// Doesnot depend on key arg, returns key and value at offset 0
printf
(
"%s
\n
"
,
value
);
file_del
(
offset
,
prevkey
);
//
file_del(offset, prevkey);
}
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