Skip to content

refac: replace vector into map #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

minseoc03
Copy link

@minseoc03 minseoc03 commented May 14, 2025

Resolves #2

Summary

This PR refactors the core date structures in llvm-block to improve performance and memory usage.

  • Replace the std::vector<collist*> table with TableMap = std::unordered_map<int, collist*> (keyed by line number).
  • Replace the std::list<col*>cols inside collist with `std::unordered_map<int, col*> (keyed by column number)
  • Update all lookup sites (CreateTable, InsertTable, CompareLR) to use fast map.find() instead of linear scans or repeated resize().

Motivation

  • Sparse line numbers are common after optimization or macro expansion; the old vector approach wasted memory and spent time resizing.
  • std::list lookups in searchcol() were O(n) in the number of columns; switching to unordered_map yields amortized O(1) lookups.

What's Changed

llvm-block.cpp

  • Swapped std::vector<collist*> table for using TableMap = std::unordered_map<int, collist*>
  • Replaced every table.at(line) + resize() pattern with table.find(line) + insert-if-missing.
  • Updated CreateTable(), InsertTable(), and CompareLR() to use the new map.

table.h/table.cpp

  • Changed collist::cols from std::list<col*> to std::unordered_map<int, col*>
  • Rewrote push(col*) and searchcol(int) to use cols.find() for O(1) insert / lookup.

@eomiso eomiso self-requested a review May 16, 2025 07:11
@eomiso eomiso self-assigned this May 16, 2025
@eomiso eomiso changed the title feat: replace vector into map refac: replace vector into map May 16, 2025
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.

feat: replace std::vector<collist*> with std::map or std::unordered_map
2 participants