Skip to content

Conversation

@ersutera
Copy link

@ersutera ersutera commented Oct 4, 2025

sort is a command to sort lines of text in alphabetical order.

How to use:
sort ./example.txt (flags)

Flags:
-u: only list unique entries
-r: reverse list

Tests for my project:
tests/test1.txt
tests/test2.txt
tests/test3.txt
tests/test4.txt

@VivianBelle17
Copy link

I'll be code reviewing this

@MichaelBooyers
Copy link

I'll be code reviewing this as well

@PiePaing
Copy link

PiePaing commented Oct 6, 2025

I'll be code reviewing this

@MichaelBooyers
Copy link

Verification

Hey Enrico! Looking at what you put for your issue and comparing to your pull request. Mostly everything said was implemented (besides the -n but you did the other two so I personally don't think it's too bad). The functionality of sort as well of the flags are really good! The only issue was starting up the qemu. Because you also added in strace, and other aspects from lab, I needed to chmod +x generate-traces.sh as before I would get permission denied. Other than this hiccup, everything compiled and worked.

Testing

For testing I tried a various amounts of versions of moving flags around. When it came to testing I didn't find any bugs. The test cases you provided were very good and represented a lot of cases. I went ahead and tried more combinations to the text files such as putting an empty space, capitalization, and the same words with various capitalization and it works as well! Overall your code seems to cover a good base of edge cases and inputs! Also I tried to throw the flags around in different cases such as 'sort test.txt -r -u' and 'sort -u -r test.txt' and the code does recognize these flags and they work so awesome!

Code Walkthrough

Your code is clear and with your comments you put, it's fairly easy to see what's happening with our code and data that we put in. I did note you did bubble sort which can either be the fastest or slowest sorting algorithm so as a possible refactor, we could implement a different algorithm based on the size of the file? Perhaps if it's a small file with 3 lines, then let's execute bubble sort, but now if we do reach our max lines of 256, maybe we could instead sort by doing merge/quick sort? Besides this small possible change, everything looks good and works just as well!

High Level Checks:
[X] PR fully resolves the task/issue. (Although it technically resolves the task, consider the note I left to make it less confusing for the user)
[X] Does the PR have tests?
[X] Does the PR follow project code formatting standards?
[X] Does the OS still compile and run?
[X] Is documentation included?

Code Checks:
[X] Does the code achieve its intended purpose?
[X] Were all edge cases considered?
[X] Is the code organized and maintainable?
[X] Does the code maintain the same level of performance?

@VivianBelle17
Copy link

VivianBelle17 commented Oct 11, 2025

Great job!! Everything works as intended!

Verification

Overall, your implementation works as expected! But according to your issue description #18, you included -n as a flag but it is not implemented here.

Testing

I ran all the tests you provided and some additional ones as well including empty, single-lined, already sorted, mixed characters, and duplicate files produced the expected results. The -r and -u flags also worked when used separately as well.

Your error handling is implemented well! For example, when trying to open a non-existent file, it returns:
sort: cannot open tests/nowhere.txt which nicely communicates user error.

Code Walkthrough

A few notes:

  • I did notice that you accidently implemented your lab 4 in here instead of your personal one so you might want to move that back before anything gets merged.
  • For code readability, I would suggest using slightly more descriptive variable names instead of single letters like m or p, specifically in user/sort.c lines 43-52.
  • Also, while the current bubble sort implementation works well for small files, it may become inefficient for larger files.
  • The documentation you provided is useful but it could be expanded a little to clarify what the output is for each flag or test file. Since that's a little difficult for sort (because there will be mainly whitespace), brief descriptions or sample outputs would make it easier to know what you believe the expected output to be (just in case of any errors on either your or our end).

Once again, great job!


High Level Checks:

  • PR fully resolves the task/issue
  • Does the PR have tests?
  • Does the PR follow project code formatting standards?
  • Does the OS still compile and run?
  • Is documentation included?

Code Checks:

  • Does the code achieve its intended purpose?
  • Were all edge cases considered?
  • Is the code organized and maintainable?
  • Does the code maintain the same level of performance? (no performance regressions)

@PiePaing
Copy link

Verification

Hey! Looking at your implementation, you've successfully implemented both the sort utility and system call tracing functionality. The sort command works exactly as specified with the -u and -r flags, and the strace implementation is comprehensive and well-documented. Everything compiles and runs correctly after making the generate-traces.sh script executable.

Testing

I tested your sort implementation with various combinations of flags and inputs:

  • ✅ All 4 test files work correctly
  • ✅ Flags work in different orders (sort -r -u test.txt and sort test.txt -u -r)
  • ✅ Edge cases like empty lines, duplicates, and mixed capitalization work properly
  • ✅ Error handling is good - proper error messages for non-existent files
  • ✅ The strace functionality works as demonstrated in your documentation

Your test cases cover a good range of scenarios and the implementation handles edge cases well!

Code Walkthrough

Your code is well-structured and easy to follow:

Sort Implementation:

  • Clean command-line parsing logic
  • Proper handling of both file input and stdin
  • Bubble sort is appropriate for the expected small datasets
  • Good error handling and user feedback

Strace Implementation:

  • Excellent architecture with proper separation of concerns
  • The auto-generation approach in generate-traces.sh is innovative
  • Safe string handling with copyinstr()
  • Comprehensive documentation in strace_documentation.md

Minor Suggestions:

  • Consider more descriptive variable names (like line_count instead of m in the file reading loop)
  • The bubble sort works well for small files, but could consider a more efficient algorithm for larger datasets if needed in the future

High Level Checks

  • PR fully resolves the task/issue - Both sort and strace functionality implemented correctly
  • Does the PR have tests? - Yes, 4 comprehensive test files provided
  • Does the PR follow project code formatting standards? - Follows xv6 conventions well
  • Does the OS still compile and run? - Compiles and runs correctly
  • Is documentation included? - Excellent documentation provided

Code Checks

  • Does the code achieve its intended purpose? - Yes, both features work as specified
  • Were all edge cases considered? - Good coverage of edge cases
  • Is the code organized and maintainable? - Well-structured and documented
  • Does the code maintain the same level of performance? - No performance regressions

Final Assessment

Great job! Your implementation is solid and meets all the requirements. The code is clean, well-documented, and handles edge cases appropriately. The strace implementation is particularly impressive with its comprehensive approach and excellent documentation.

Recommendation: ✅ APPROVE

The only minor suggestions are about variable naming and potential future optimizations, but these don't affect the functionality or quality of your current implementation. Everything works as intended!

@malensek
Copy link
Contributor

Verification

Hey! Looking at your implementation, you've successfully implemented both the sort utility and system call tracing functionality. The sort command works exactly as specified with the -u and -r flags, and the strace implementation is comprehensive and well-documented. Everything compiles and runs correctly after making the generate-traces.sh script executable.

Testing

I tested your sort implementation with various combinations of flags and inputs:

  • ✅ All 4 test files work correctly
  • ✅ Flags work in different orders (sort -r -u test.txt and sort test.txt -u -r)
  • ✅ Edge cases like empty lines, duplicates, and mixed capitalization work properly
  • ✅ Error handling is good - proper error messages for non-existent files
  • ✅ The strace functionality works as demonstrated in your documentation

Your test cases cover a good range of scenarios and the implementation handles edge cases well!

Code Walkthrough

Your code is well-structured and easy to follow:

Sort Implementation:

  • Clean command-line parsing logic
  • Proper handling of both file input and stdin
  • Bubble sort is appropriate for the expected small datasets
  • Good error handling and user feedback

Strace Implementation:

  • Excellent architecture with proper separation of concerns
  • The auto-generation approach in generate-traces.sh is innovative
  • Safe string handling with copyinstr()
  • Comprehensive documentation in strace_documentation.md

Minor Suggestions:

  • Consider more descriptive variable names (like line_count instead of m in the file reading loop)
  • The bubble sort works well for small files, but could consider a more efficient algorithm for larger datasets if needed in the future

High Level Checks

  • PR fully resolves the task/issue - Both sort and strace functionality implemented correctly
  • Does the PR have tests? - Yes, 4 comprehensive test files provided
  • Does the PR follow project code formatting standards? - Follows xv6 conventions well
  • Does the OS still compile and run? - Compiles and runs correctly
  • Is documentation included? - Excellent documentation provided

Code Checks

  • Does the code achieve its intended purpose? - Yes, both features work as specified
  • Were all edge cases considered? - Good coverage of edge cases
  • Is the code organized and maintainable? - Well-structured and documented
  • Does the code maintain the same level of performance? - No performance regressions

Final Assessment

Great job! Your implementation is solid and meets all the requirements. The code is clean, well-documented, and handles edge cases appropriately. The strace implementation is particularly impressive with its comprehensive approach and excellent documentation.

Recommendation: ✅ APPROVE

The only minor suggestions are about variable naming and potential future optimizations, but these don't affect the functionality or quality of your current implementation. Everything works as intended!

Nice, even checked over Lab 3 for me! 🙏

@malensek
Copy link
Contributor

Uh oh, looks like you are using this repo for your labs. Those should be checked into your private repo.

This sort implementation looks good. I have nothing against bubble sort here. However, one big limitation is the fixed-size array, which is very small for both lines and line lengths.

This needs to dynamically allocate both (using malloc) to be functional, also from an efficiency standpoint: instead of storing fixed-sized lines that you'd have to hard-code, you could store a "jagged" array of pointers to dynamically-sized strings.

I'd write a a couple of helper functions to do this, but the basic idea would be to copy what Java's ArrayList does and double the size of the allocation each time you need more space (and then free the old memory).

The getline example we used in the last lab is pretty close to being functional for this, although we'd need to modify it a bit to work in this situation.

4.5/5

+0.5 -> dynamic sizes for lines / line lengths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants