import Branch from "./branch";
import Commit from "./commit";

export class GraphColumns<TNode> {
  private columns: Array<Branch["name"]> = [];

  /**
   * Compute the graph columns from commits.
   *
   * @param commits List of graph commits
   */
  public constructor(commits: Array<Commit<TNode>>) {
    this.columns = [];
    commits.forEach((commit) => {
      const branch = commit.branchToDisplay;
      if (!this.columns.includes(branch)) this.columns.push(branch);
    });
  }

  /**
   * Return the column index corresponding to given branch name.
   *
   * @param branchName Name of the branch
   */
  public get(branchName: Branch["name"]): number {
    return this.columns.findIndex((col) => col === branchName);
  }
}

import Branch from "./branch";
import Commit from "./commit";

export class GraphColumns<TNode> {
  private branches: Set<Branch["name"]> = new Set();

  public constructor(commits: Array<Commit<TNode>>) {
    commits.forEach((commit) => this.branches.add(commit.branchToDisplay));
  }

  /**
   * Return the column index corresponding to given branch name.
   *
   * @param branchName Name of the branch
   */
  public get(branchName: Branch["name"]): number {
    return Array.from(this.branches).findIndex(
      (branch) => branch === branchName,
    );
  }
}

Refactor GraphColumns to use a Set()
Refactor GraphColumns to use a Set()
