Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In rust language In this problem you are to write a program fgroups (short for fingerprint groups), which when given a set of names with

In rust language

In this problem you are to write a program fgroups (short for fingerprint groups), which when given a set of names with fingerprints will identify groups of names that share a fingerprint. The real object of the exercise is to familiarize you with some parts of the standard library.

Your input is always on standard input. Input is a sequence of lines where each line has the following format:

The line begins with one or more non-whitespace characters. This sequence of characters is the fingerprint.

The fingerprint is followed by one or more whitespace characters, not including newline.

The name begins with the next non-whitespace character and continues through the next newline. A name may contain whitespace, but a name never contains a newline.

As an example of this, if a line of input is fingerprint this is my name, then the resulting fingerprint would be fingerprint and the resulting name would be this is my name.

For this part of the assignment, you may not use any external crates, but can use anything in the standard library (std::)

Finally, you may also assume that each name appears at most once. You may assume that a fingerprint is at most 512 characters long (2048 bits represented in hexadecimal notation), but there is no a priori upper bound on the length of a name.

What to do with good input

By the nature of the input, every fingerprint you read will be associated with at least one name.

If a fingerprint is associated with exactly one name, ignore the fingerprint (and the name).

If a fingerprint is associated with two or more names, those names consti- tute a fingerprint group. A fingerprint group always has at least two members.

Your program should print all the fingerprint groups in the following format:

If there are no fingerprint groups, print nothing. If there is exactly one fingerprint group, print it.

If there are multiple fingerprint groups, print them separated by newlines.

Groups may be printed in any order.

To print a fingerprint group, print each name in the group. Put a newline after each name; the println!() macro will help you here. Names within the group may be printed in any order.

For example, if the input is

A Ron

A Poppy

B Bill

A Dubya

B Barry

A Orange

B Joe

Then one possible output is

 Ron Dubya Poppy Orange 
 Bill Barry Joe 

(This example output contains exactly one blank line.)

What to do with bad input

If you get an input line that is badly formed, write an error message to stderr, discard the badly formed line, and continue.

If you get a fingerprint of more than 512 characters, you may choose to write an error message to stderr, discard the line, and continueor you may handle the oversize fingerprint correctly. In other words, your program doesnt need to handle fingerprints larger than 512 characters, but you wont be penalized if it does. In Rust, the simplest thing is to just handle fingerprints of any length, without truncating.

Your program should handle any name that can appear in the filesystem; if you get a name that is longer than you can handle, write a suitable message to stderr, truncate the name, and use the truncated name with the given fingerprint. In Rust, you should be able to handle anything that fits within memory, so dont worry about truncating anything.

If a name appears more than once, your program may silently give wrong answers, but it must not print an error, crash, or commit memory errors.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

2. Place a value on the outcomes.

Answered: 1 week ago