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
2a343ede
Commit
2a343ede
authored
Nov 08, 2020
by
Roshan Rabinarayan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed file_put to use memcpy
parent
a5d82517
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
44 deletions
+16
-44
temp.c
temp.c
+16
-44
No files found.
temp.c
View file @
2a343ede
...
@@ -34,32 +34,28 @@ void file_del(char *key)
...
@@ -34,32 +34,28 @@ void file_del(char *key)
int
index
=
modulus
(
key
,
256
,
setSize
);
int
index
=
modulus
(
key
,
256
,
setSize
);
sem_wait
(
&
mutex
[
index
]);
sem_wait
(
&
mutex
[
index
]);
FILE
*
fp
;
FILE
*
fp
;
char
*
line
=
NULL
;
char
*
line
=
malloc
(
sizeof
(
char
)
*
514
)
;
size_t
len
=
0
;
size_t
len
=
0
;
int
read
;
int
read
;
fp
=
fdopen
(
fds
[
index
],
"
a+
"
);
fp
=
fdopen
(
fds
[
index
],
"
r+b
"
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
printf
(
"
\n
[Invalid file]
\n
"
);
printf
(
"
\n
[Invalid file]
\n
"
);
int
position
=
0
;
int
position
=
ftell
(
fp
)
;
while
(
(
read
=
getline
(
&
line
,
&
len
,
fp
))
!=
-
1
)
while
(
fscanf
(
fp
,
"%s"
,
line
)
!=
EOF
)
{
{
if
(
strstr
(
line
,
key
)
!=
NULL
&&
strstr
(
strstr
(
line
,
key
),
":"
)
!=
NULL
)
if
(
strstr
(
line
,
key
)
!=
NULL
&&
strstr
(
strstr
(
line
,
key
),
":"
)
!=
NULL
)
{
{
//printf("%s\n",line);
fseek
(
fp
,
position
,
SEEK_SET
);
printf
(
"%d"
,
fseek
(
fp
,
position
,
SEEK_SET
));
fprintf
(
fp
,
"%s"
,
"
\0
"
);
break
;
break
;
}
}
else
position
=
ftell
(
fp
);
{
printf
(
"
\n
%d "
,
position
);
position
+=
len
;
}
}
}
//fclose(fp);
if
(
line
)
if
(
line
)
free
(
line
);
free
(
line
);
sem_wait
(
&
readerLocks
[
index
]);
sem_wait
(
&
readerLocks
[
index
]);
...
@@ -112,41 +108,16 @@ void file_put(char *key,char *value)
...
@@ -112,41 +108,16 @@ void file_put(char *key,char *value)
sem_wait
(
&
mutex
[
index
]);
sem_wait
(
&
mutex
[
index
]);
printf
(
"
\n
[Write to File: %d]
\n
"
,
index
);
printf
(
"
\n
[Write to File: %d]
\n
"
,
index
);
char
line
[
514
];
char
line
[
514
];
int
i
=
0
;
memcpy
(
line
,
key
,
256
);
for
(
i
=
0
;
i
<
256
;
i
++
)
line
[
strlen
(
key
)]
=
':'
;
{
memcpy
(
line
+
strlen
(
line
),
value
,
256
);
if
(
key
[
i
]
!=
'\0'
)
line
[
strlen
(
line
)]
=
'\n'
;
{
line
[
i
]
=
key
[
i
];
}
else
{
break
;
}
}
int
k
=
0
;
line
[
i
++
]
=
':'
;
for
(;
i
<
512
;
i
++
)
{
if
(
value
[
k
]
!=
'\0'
)
{
line
[
i
]
=
value
[
k
++
];
}
else
{
break
;
}
}
line
[
i
]
=
'\n'
;
if
(
write
(
fds
[
index
],
line
,
strlen
(
line
))
<
0
)
if
(
write
(
fds
[
index
],
line
,
strlen
(
line
))
<
0
)
{
{
printf
(
"
\n
[Unable to Write to File]
\n
"
);
printf
(
"
\n
[Unable to Write to File]
\n
"
);
}
}
sem_post
(
&
mutex
[
index
]);
sem_post
(
&
mutex
[
index
]);
}
}
int
main
()
int
main
()
{
{
/*
/*
...
@@ -155,11 +126,12 @@ int main()
...
@@ -155,11 +126,12 @@ int main()
PUT,DEL would use write lock
PUT,DEL would use write lock
GET would use read lock
GET would use read lock
each write should return the line number
each write should return the line number
*/
*/
int
n2
=
0
;
int
n2
=
0
;
char
key
[
256
]
=
"24"
;
char
key
[
256
]
=
"24"
;
char
value
[
256
]
=
"value"
;
char
value
[
256
]
=
"value"
;
bzero
(
key
+
strlen
(
key
),
sizeof
(
key
)
-
strlen
(
key
));
bzero
(
value
+
strlen
(
value
),
sizeof
(
value
)
-
strlen
(
value
));
fds
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
setSize
);
fds
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
setSize
);
readCounters
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
setSize
);
readCounters
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
setSize
);
readerLocks
=
(
sem_t
*
)
malloc
(
sizeof
(
sem_t
)
*
setSize
);
readerLocks
=
(
sem_t
*
)
malloc
(
sizeof
(
sem_t
)
*
setSize
);
...
...
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