Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_144 - B+ Tree Project
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_144 - B+ Tree Project
Commits
746689e8
Commit
746689e8
authored
2 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Comment DirectoryRecord
parent
15d3386f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
main.c
+1
-1
1 addition, 1 deletion
main.c
src/Array.h
+3
-3
3 additions, 3 deletions
src/Array.h
src/Directory.c
+0
-1
0 additions, 1 deletion
src/Directory.c
src/DirectoryRecord.c
+23
-11
23 additions, 11 deletions
src/DirectoryRecord.c
src/DirectoryRecord.h
+49
-1
49 additions, 1 deletion
src/DirectoryRecord.h
with
76 additions
and
17 deletions
main.c
+
1
−
1
View file @
746689e8
...
...
@@ -100,7 +100,7 @@ void delete_record(Directory *directory) {
printf
(
"
\n
===>The procedure has been cancelled.
\n
"
);
}
else
{
Directory_delete
(
directory
,
phone_number
);
printf
(
"
Delete done
\n
"
);
printf
(
"
The record has been deleted from the directory.
\n
"
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Array.h
+
3
−
3
View file @
746689e8
...
...
@@ -31,7 +31,7 @@ typedef struct IntegerArray {
IntegerArray
*
IntegerArray_init
(
int
capacity
);
/**
* @brief Destroy the array and free its memory.
* @brief Destroy
s
the array and free its memory.
*
* @param array The array to be destroyed.
*/
...
...
@@ -135,7 +135,7 @@ typedef struct BPTreeNodeArray {
BPTreeNodeArray
*
BPTreeNodeArray_init
(
int
capacity
);
/**
* @brief Destroy the array and free its memory.
* @brief Destroy
s
the array and free its memory.
*
* @param array The array to be destroyed.
*/
...
...
@@ -210,7 +210,7 @@ typedef struct ByteArray {
ByteArray
*
ByteArray_init
(
int
capacity
);
/**
* @brief Destroy the array and free its memory.
* @brief Destroy
s
the array and free its memory.
*
* @param array The array to be destroyed.
*/
...
...
This diff is collapsed.
Click to expand it.
src/Directory.c
+
0
−
1
View file @
746689e8
...
...
@@ -16,7 +16,6 @@
#include
"Array.h"
#include
"BPTree.h"
#include
"DirectoryRecord.h"
// CAUTION : Je devrais refactor l'implémentation avec le FILE.
static
uint64_t
hash_string
(
char
*
str
)
{
SHA256_CTX
sha256
;
...
...
This diff is collapsed.
Click to expand it.
src/DirectoryRecord.c
+
23
−
11
View file @
746689e8
/**
* @file DirectoryRecord.c
* @author Florian Burgener (florian.burgener@etu.hesge.ch)
* @brief
* @brief
A record that represents a member of the organization.
* @version 1.0
* @date 2022-06-XX
*/
...
...
@@ -16,7 +16,8 @@
#include
"Array.h"
int
DirectoryRecord_size_on_disk
()
{
int
size
=
1
;
int
size
=
0
;
size
+=
IS_DELETED_SIZE_IN_BYTES
;
size
+=
PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER
;
size
+=
NAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
size
+=
SURNAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
...
...
@@ -54,26 +55,31 @@ void DirectoryRecord_print(DirectoryRecord *record) {
ByteArray
*
DirectoryRecord_to_ByteArray
(
DirectoryRecord
*
record
)
{
int
capacity
=
DirectoryRecord_size_on_disk
();
ByteArray
*
array
=
ByteArray_init
(
capacity
);
// Convert the "is_deleted" field to byte.
ByteArray_append
(
array
,
(
uint8_t
)
record
->
is_deleted
);
for
(
int
j
=
0
;
j
<
PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
phone_number
[
j
]);
// Converts each character of the phone number to byte.
for
(
int
i
=
0
;
i
<
PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER
;
i
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
phone_number
[
i
]);
}
for
(
int
j
=
0
;
j
<
NAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
name
[
j
]);
// Converts each character of the name to byte.
for
(
int
i
=
0
;
i
<
NAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
i
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
name
[
i
]);
}
for
(
int
j
=
0
;
j
<
SURNAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
surname
[
j
]);
// Converts each character of the surname to byte.
for
(
int
i
=
0
;
i
<
SURNAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
i
++
)
{
ByteArray_append
(
array
,
(
uint8_t
)
record
->
surname
[
i
]);
}
//
Birth Date : Year
//
Converts the year of birth to bytes.
ByteArray_append
(
array
,
(
uint8_t
)((
record
->
birth_date_year
>>
8
)
&
255
));
ByteArray_append
(
array
,
(
uint8_t
)(
record
->
birth_date_year
&
255
));
//
Birth Date : Month
//
Converts the month of birth to byte.
ByteArray_append
(
array
,
(
uint8_t
)
record
->
birth_date_month
);
//
Birth Date : Day
//
Converts the day of birth to byte.
ByteArray_append
(
array
,
(
uint8_t
)
record
->
birth_date_day
);
return
array
;
...
...
@@ -81,12 +87,15 @@ ByteArray *DirectoryRecord_to_ByteArray(DirectoryRecord *record) {
DirectoryRecord
*
ByteArray_to_DirectoryRecord
(
ByteArray
*
byte_array
)
{
int
i
=
0
;
// Initliases the "is_deleted" variable with the first byte.
bool
is_deleted
=
(
bool
)
byte_array
->
items
[
i
];
i
++
;
char
phone_number
[
PHONE_NUMBER_MAXLEN
];
phone_number
[
PHONE_NUMBER_MAXLEN
-
1
]
=
'\0'
;
// Read the bytes of the phone number and reconstruct the string of characters.
for
(
int
j
=
0
;
j
<
PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
phone_number
[
j
]
=
(
char
)
byte_array
->
items
[
i
];
i
++
;
...
...
@@ -95,6 +104,7 @@ DirectoryRecord *ByteArray_to_DirectoryRecord(ByteArray *byte_array) {
char
name
[
NAME_MAXLEN
];
name
[
NAME_MAXLEN
-
1
]
=
'\0'
;
// Read the bytes of the name and reconstruct the string of characters.
for
(
int
j
=
0
;
j
<
NAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
name
[
j
]
=
(
char
)
byte_array
->
items
[
i
];
i
++
;
...
...
@@ -103,11 +113,13 @@ DirectoryRecord *ByteArray_to_DirectoryRecord(ByteArray *byte_array) {
char
surname
[
SURNAME_MAXLEN
];
surname
[
SURNAME_MAXLEN
-
1
]
=
'\0'
;
// Read the bytes of the surname and reconstruct the string of characters.
for
(
int
j
=
0
;
j
<
SURNAME_MAXLEN_WITHOUT_NULL_CHARACTER
;
j
++
)
{
surname
[
j
]
=
(
char
)
byte_array
->
items
[
i
];
i
++
;
}
// Reconstitutes the date of birth from the bytes.
int
birth_date_year
=
(
int
)
byte_array
->
items
[
i
]
<<
8
|
(
int
)
byte_array
->
items
[
i
+
1
];
int
birth_date_month
=
(
int
)
byte_array
->
items
[
i
+
2
];
int
birth_date_day
=
(
int
)
byte_array
->
items
[
i
+
3
];
...
...
This diff is collapsed.
Click to expand it.
src/DirectoryRecord.h
+
49
−
1
View file @
746689e8
/**
* @file DirectoryRecord.h
* @author Florian Burgener (florian.burgener@etu.hesge.ch)
* @brief
* @brief
A record that represents a member of the organization.
* @version 1.0
* @date 2022-06-XX
*/
...
...
@@ -12,6 +12,8 @@
#include
"Array.h"
#define IS_DELETED_SIZE_IN_BYTES 1
#define PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER 10
#define PHONE_NUMBER_MAXLEN 1 + PHONE_NUMBER_MAXLEN_WITHOUT_NULL_CHARACTER
...
...
@@ -23,6 +25,10 @@
#define BIRTH_DATE_SIZE_IN_BYTES 4
/**
* @brief Data structure that represents a record.
*
*/
typedef
struct
DirectoryRecord
{
bool
is_deleted
;
char
phone_number
[
PHONE_NUMBER_MAXLEN
];
...
...
@@ -33,13 +39,55 @@ typedef struct DirectoryRecord {
int
birth_date_day
;
}
DirectoryRecord
;
/**
* @brief Size in bytes that a record takes when written on disk.
*
* @return int Size in bytes.
*/
int
DirectoryRecord_size_on_disk
();
/**
* @brief Initializes the "DirectoryRecord" data structure.
*
* @param is_deleted false = the record is not deleted, true = the record is deleted.
* @param phone_number The phone number.
* @param name The name.
* @param surname The surname.
* @param birth_date_year The year of birth.
* @param birth_date_month The month of birth.
* @param birth_date_day The day of birth.
* @return DirectoryRecord* The record initialized with the data.
*/
DirectoryRecord
*
DirectoryRecord_init
(
bool
is_deleted
,
char
phone_number
[
PHONE_NUMBER_MAXLEN
],
char
name
[
NAME_MAXLEN
],
char
surname
[
SURNAME_MAXLEN
],
int
birth_date_year
,
int
birth_date_month
,
int
birth_date_day
);
/**
* @brief Destroys the record and free its memory.
*
* @param record The record to be destroyed.
*/
void
DirectoryRecord_destroy
(
DirectoryRecord
**
record
);
/**
* @brief Displays the record on the console.
*
* @param record The record to display.
*/
void
DirectoryRecord_print
(
DirectoryRecord
*
record
);
/**
* @brief Converts a record into an array of bytes.
*
* @param record The record to be converted.
* @return ByteArray* The resulting byte array.
*/
ByteArray
*
DirectoryRecord_to_ByteArray
(
DirectoryRecord
*
record
);
/**
* @brief Converts an array of bytes into a record.
*
* @param byte_array The array of bytes to be converted.
* @return DirectoryRecord* The resulting record.
*/
DirectoryRecord
*
ByteArray_to_DirectoryRecord
(
ByteArray
*
byte_array
);
#endif
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