ShahjalalShohag / code-library

Templates, algorithms and data structures implemented and collected for programming contests.
MIT License
2.83k stars 747 forks source link

Looking for Well Structured and Well Documented Code #24

Closed ShahjalalShohag closed 3 weeks ago

ShahjalalShohag commented 11 months ago

Most files do not contain generalized and well-documented codes. For example for the following segment tree code:

struct ST {
  int t[4 * N];
  static const int inf = 1e9;
  ST() {
    memset(t, 0, sizeof t);
  }
  void build(int n, int b, int e) {
    if (b == e) {
      t[n] = a[b];
      return;
    }
    int mid = (b + e) >> 1, l = n << 1, r = l | 1;
    build(l, b, mid);
    build(r, mid + 1, e);
    t[n] = max(t[l], t[r]);
  }
  void upd(int n, int b, int e, int i, int x) {
    if (b > i || e < i) return;
    if (b == e && b == i) {
      t[n] = x;
      return;
    }
    int mid = (b + e) >> 1, l = n << 1, r = l | 1;
    upd(l, b, mid, i, x);
    upd(r, mid + 1, e, i, x);
    t[n] = max(t[l], t[r]);
  }
  int query(int n, int b, int e, int i, int j) {
    if (b > j || e < i) return -inf;
    if (b >= i && e <= j) return t[n];
    int mid = (b + e) >> 1, l = n << 1, r = l | 1;
    int L = query(l, b, mid, i, j);
    int R = query(r, mid + 1, e, i, j);
    return max(L, R);
  }
}t;

A better approach would be:

Example PR: https://github.com/ShahjalalShohag/code-library/pull/25

Check the whole codebase, you will be able to find lots of files where you can work on similar stuff.

Contribution Steps:

  1. Identify Areas for Improvement: Scan through the codebase and identify files or components where similar issues can be fixed or optimized.

  2. Fix Issues: Make the necessary changes in a new branch. Ensure that you adhere to the project's coding guidelines and that your changes are well-documented.

  3. Open a Pull Request: After completing your changes, please open a pull request for review.

Once your PR is submitted, it will be reviewed and, if approved, merged into the main branch.

Thank you for your contribution!

spy-1234 commented 11 months ago

Hey, I would like to work on the issue.

ShahjalalShohag commented 11 months ago

@spy-1234 Please look through the codebase, you will be able to find multiple files with similar stuff to work on. After fixing some issues, open a PR. I will review and merge it.