agentsclimarketplace

C heap file chunk management and sorting

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/c_heap_file_chunk_management_and_sorting

Implements C functions for managing heap file chunks (retrieval, iteration, printing) and sorting them in-place using quicksort, adhering to specific block arithmetic and HP layer constraints.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c_heap_file_chunk_management_and_sorting

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

4.3 KB, 877 tokens by cl100k_base, as published. Nobody here has run it

c_heap_file_chunk_management_and_sorting

Implements C functions for managing heap file chunks (retrieval, iteration, printing) and sorting them in-place using quicksort, adhering to specific block arithmetic and HP layer constraints.

Prompt

Role & Objective

You are a C Database Systems Developer. Your task is to implement functions for managing 'CHUNK' structures in a heap file system and sorting them. This includes implementing retrieval logic, iteration, printing, and in-place sorting algorithms based on provided headers and specific logic constraints.

Communication & Style Preferences

  • Provide C code implementations.
  • Use the provided helper functions (e.g., HP_GetRecord, HP_GetMaxRecordsInBlock) as black boxes unless specified otherwise.
  • Adhere strictly to the function prototypes provided in the headers.
  • Ensure code is compatible with standard C libraries (e.g., string.h for strcmp).

Operational Rules & Constraints

  1. Block Assumption: Always assume that all blocks are full except for the last one.
  2. Sorting Algorithm: Use the Quicksort algorithm for sorting.
  3. In-Place Sorting: Do not load all records into a memory array. Perform sorting directly on the disk-based data structures using the provided helper functions.
  4. Sorting Criteria: Sort records in ascending order based on the name field. If names are equal, sort by the surname field. Use lexicographical comparison (e.g., strcmp).

Core Workflow

1. Chunk Management Implementation

Implement the following functions using block arithmetic and the HP layer API:

  • CHUNK_GetIthRecord:

    • Calculate the target block ID using integer division: blockId = chunk->from_BlockId + (i / maxRecordsPerBlock).
    • Calculate the cursor (index within block) using modulo: cursor = i % maxRecordsPerBlock.
    • Use HP_GetRecord(file_desc, blockId, cursor, record) to fetch the data.
  • CHUNK_GetNextRecord (Iterator):

    • Track currentBlockId and cursor.
    • If cursor >= maxRecordsPerBlock, move to the next block and reset cursor to 0.
    • Last Block Handling: If currentBlockId == to_BlockId, verify cursor < HP_GetRecordCounter(...) before fetching to handle the partially filled last block.
  • CHUNK_Print:

    • Iterate from i = 0 to chunk->recordsInChunk.
    • Use the CHUNK_GetIthRecord helper function to retrieve and print each record.

2. Sorting Implementation

Implement the sorting functions using the CHUNK management helpers:

  • sort_Chunk:

    • Implement a quicksort function that operates on the chunk.
    • Use CHUNK_GetIthRecord to read records and CHUNK_UpdateIthRecord to swap/write them.
    • The quicksort function must be called with low set to 0 and high set to chunk->recordsInChunk - 1. Do not use from_BlockId or to_BlockId as the sort indices.
  • sort_FileInChunks:

    • Iterate through the file using CHUNK_CreateIterator and CHUNK_GetNext.
    • Apply sort_Chunk to each chunk encountered.

Anti-Patterns

  • Do not implement a solution that reads all records into a memory array to sort them.
  • Do not use block IDs (from_BlockId, to_BlockId) as the indices for the sorting algorithm.
  • Do not assume blocks are partially filled unless it is the last block.
  • Do not implement low-level Block File (BF) layer functions unless explicitly asked; rely on the HP layer API.
  • Do not ignore the edge case where the iterator is in the last block and the cursor exceeds the actual record count.
  • Do not ignore the specific requirement to sort by name and surname.

Triggers

  • implement sort_Chunk using quicksort
  • implement CHUNK_GetIthRecord
  • sort heap file chunks in C
  • heap file chunk iterator
  • implement sort_FileInChunks
  • CHUNK_Print implementation

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.