<commit_before>//-----------------------------------------------------------------------------
// A simple task manager for use with Grunt. Avoids duplicate subtasks.
//
// Compile using the command:
// $ tsc --module commonjs tools/taskmanager.ts

//-----------------------------------------------------------------------------
// Assumes tasks have tree-shaped constructive dependencies: assumes that if a
// component was build once, then it never has to be build again in a single
// build run.
// i.e. given: A = [B,C,Z], B = [X1,X2], C = [X1,Y], then A = [X1,X2,Y,Z],
// i.e. only constraint is that index(X1) < index(Y), and that steps after
// X1 in B do not disrupt steps C.

module TaskManager {

  export interface Index { [s:string]: string[] };

  // The state of flattening a tree.
  class FlatteningState {
    // Flattened tree seen so far.
    flattened_: string[] = [];
    // Elements still to be flattened.
    queue_: string[] = [];
    // Elements seen.
    seen_: { [s:string] : boolean } = {};

    // Create an initial state with a single top-level name in the queue.
    constructor(name: string) {
      this.queue([name]);
    }

    // True when the given node name has been seen before.
    public haveSeen(name: string) { return (name in this.seen_); }

    // True all nodes have been flattened.
    public isFlattened() { return (this.queue_.length == 0); }

    // unfold a node in the flattening process. This either adds it to the
    // list of flattened nodes, or adds its children to the queue. Either way,
    // the node is marked as seen.
    unfoldNode(index : Index, name:string) {
      if(this.haveSeen(name)) { return; }
      this.seen_[name] = true;
      if(name in index) {
        this.queue(index[name]);
      } else {
        this.flattened_.push(name);
      }
    }

    // Add node names to the queue.
    public queue(toQueue : string[]) {
      this.queue_ = toQueue.concat(this.queue_);
    }

    // Flatten the state w.r.t. the given index.
    public flatten(index : Index) {
      var unfoldWrtIndex = this.unfoldNode.bind(this,index);
      while(!this.isFlattened()) {
        unfoldWrtIndex(this.queue_.shift());
      }
      return this.flattened_;
    }
  }


  export class Manager {
    // Index from task name to flattened and de-duped list of subtasks.
    private taskIndex_ : Index;

    constructor() {
      this.taskIndex_ = {};
    }

    // Assumes all tasks are defined before being added.
    public add(name : string, subtasks : string[]) {
      this.taskIndex_[name] = subtasks;
    }

    public getUnflattened(name : string) {
      if(! (name in this.taskIndex_)) {
        throw(name + " is not in taskIndex.");
      }
      return this.taskIndex_[name];
    }

    public get(name : string) {
      return (new FlatteningState(name)).flatten(this.taskIndex_);
    }

    public list() {
      return Object.keys(this.taskIndex_);
    }
  }  // class Manager

}  // module TaskManager
<commit_msg>added hackery to make compile file commonjs-compatible.<commit_after>//-----------------------------------------------------------------------------
// A simple task manager for use with Grunt. Avoids duplicate subtasks.
//
// Compile using the command:
// $ tsc --module commonjs tools/taskmanager.ts

//-----------------------------------------------------------------------------
// Assumes tasks have tree-shaped constructive dependencies: assumes that if a
// component was build once, then it never has to be build again in a single
// build run.
// i.e. given: A = [B,C,Z], B = [X1,X2], C = [X1,Y], then A = [X1,X2,Y,Z],
// i.e. only constraint is that index(X1) < index(Y), and that steps after
// X1 in B do not disrupt steps C.

module TaskManager {

  export interface Index { [s:string]: string[] };

  // The state of flattening a tree.
  class FlatteningState {
    // Flattened tree seen so far.
    flattened_: string[] = [];
    // Elements still to be flattened.
    queue_: string[] = [];
    // Elements seen.
    seen_: { [s:string] : boolean } = {};

    // Create an initial state with a single top-level name in the queue.
    constructor(name: string) {
      this.queue([name]);
    }

    // True when the given node name has been seen before.
    public haveSeen(name: string) { return (name in this.seen_); }

    // True all nodes have been flattened.
    public isFlattened() { return (this.queue_.length == 0); }

    // unfold a node in the flattening process. This either adds it to the
    // list of flattened nodes, or adds its children to the queue. Either way,
    // the node is marked as seen.
    unfoldNode(index : Index, name:string) {
      if(this.haveSeen(name)) { return; }
      this.seen_[name] = true;
      if(name in index) {
        this.queue(index[name]);
      } else {
        this.flattened_.push(name);
      }
    }

    // Add node names to the queue.
    public queue(toQueue : string[]) {
      this.queue_ = toQueue.concat(this.queue_);
    }

    // Flatten the state w.r.t. the given index.
    public flatten(index : Index) {
      var unfoldWrtIndex = this.unfoldNode.bind(this,index);
      while(!this.isFlattened()) {
        unfoldWrtIndex(this.queue_.shift());
      }
      return this.flattened_;
    }
  }


  export class Manager {
    // Index from task name to flattened and de-duped list of subtasks.
    private taskIndex_ : Index;

    constructor() {
      this.taskIndex_ = {};
    }

    // Assumes all tasks are defined before being added.
    public add(name : string, subtasks : string[]) {
      this.taskIndex_[name] = subtasks;
    }

    public getUnflattened(name : string) {
      if(! (name in this.taskIndex_)) {
        throw(name + " is not in taskIndex.");
      }
      return this.taskIndex_[name];
    }

    public get(name : string) {
      return (new FlatteningState(name)).flatten(this.taskIndex_);
    }

    public list() {
      return Object.keys(this.taskIndex_);
    }
  }  // class Manager

}  // module TaskManager

// A bit of a hack to allow this file to be compiled normally and still used by
// commonjs-style require.
var exports = (exports || {});
exports.Manager = TaskManager.Manager;

{'fraction_non_alphanumeric': 0.16585995482413682, 'fraction_numerical': 0.0025814778960955146, 'mean_word_length': 2.0964035964035963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5688361', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1789, 'n_words': 608}