Skip to content

Commit

Permalink
Change NullEdgeType to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
thebriando committed Aug 5, 2021
1 parent 8657593 commit e85fc92
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions packages/core/core/src/BundleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import {fromProjectPath} from './projectPath';
export const bundleGraphEdgeTypes = {
// A lack of an edge type indicates to follow the edge while traversing
// the bundle's contents, e.g. `bundle.traverse()` during packaging.
null: 0,
null: 1,
// Used for constant-time checks of presence of a dependency or asset in a bundle,
// avoiding bundle traversal in cases like `isAssetInAncestors`
contains: 1,
contains: 2,
// Connections between bundles and bundle groups, for quick traversal of the
// bundle hierarchy.
bundle: 2,
bundle: 3,
// When dependency -> asset: Indicates that the asset a dependency references
// is contained in another bundle.
// When dependency -> bundle: Indicates the bundle is necessary for any bundles
Expand All @@ -55,10 +55,10 @@ export const bundleGraphEdgeTypes = {
// This type prevents referenced assets from being traversed from dependencies
// along the untyped edge, and enables traversal to referenced bundles that are
// not directly connected to bundle group nodes.
references: 3,
references: 4,
// Signals that the dependency is internally resolvable via the bundle's ancestry,
// and that the bundle connected to the dependency is not necessary for the source bundle.
internal_async: 4,
internal_async: 5,
};

type BundleGraphEdgeType = $Values<typeof bundleGraphEdgeTypes>;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/core/src/ContentGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type {ContentKey, NodeId} from './types';
import Graph, {type GraphOpts} from './Graph';
import nullthrows from 'nullthrows';

export type SerializedContentGraph<TNode, TEdgeType: number = 0> = {|
export type SerializedContentGraph<TNode, TEdgeType: number = 1> = {|
...GraphOpts<TNode, TEdgeType>,
_contentKeyToNodeId: Map<ContentKey, NodeId>,
_nodeIdToContentKey: Map<NodeId, ContentKey>,
|};

export default class ContentGraph<TNode, TEdgeType: number = 0> extends Graph<
export default class ContentGraph<TNode, TEdgeType: number = 1> extends Graph<
TNode,
TEdgeType,
> {
Expand Down
28 changes: 14 additions & 14 deletions packages/core/core/src/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type {TraversalActions, GraphVisitor} from '@parcel/types';
import assert from 'assert';
import nullthrows from 'nullthrows';

type NullEdgeType = 0;
export type GraphOpts<TNode, TEdgeType: number = 0> = {|
type NullEdgeType = 1;
export type GraphOpts<TNode, TEdgeType: number = 1> = {|
nodes?: Map<NodeId, TNode>,
edges?: AdjacencyListMap<TEdgeType | NullEdgeType>,
rootNodeId?: ?NodeId,
Expand All @@ -17,12 +17,12 @@ export type GraphOpts<TNode, TEdgeType: number = 0> = {|

export const ALL_EDGE_TYPES = '@@all_edge_types';

export default class Graph<TNode, TEdgeType: number = 0> {
export default class Graph<TNode, TEdgeType: number = 1> {
nodes: Map<NodeId, TNode>;
inboundEdges: AdjacencyList<TEdgeType | NullEdgeType>;
outboundEdges: AdjacencyList<TEdgeType | NullEdgeType>;
rootNodeId: ?NodeId;
nextNodeId: number = 0;
nextNodeId: number = 1;

constructor(opts: ?GraphOpts<TNode, TEdgeType>) {
this.nodes = opts?.nodes || new Map();
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
return this.nodes.get(id);
}

addEdge(from: NodeId, to: NodeId, type: TEdgeType | NullEdgeType = 0): void {
addEdge(from: NodeId, to: NodeId, type: TEdgeType | NullEdgeType = 1): void {
if (!this.getNode(from)) {
throw new Error(`"from" node '${fromNodeId(from)}' not found`);
}
Expand All @@ -114,14 +114,14 @@ export default class Graph<TNode, TEdgeType: number = 0> {
hasEdge(
from: NodeId,
to: NodeId,
type?: TEdgeType | NullEdgeType = 0,
type?: TEdgeType | NullEdgeType = 1,
): boolean {
return this.outboundEdges.hasEdge(from, to, type);
}

getNodeIdsConnectedTo(
nodeId: NodeId,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 0,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
): Array<NodeId> {
this._assertHasNodeId(nodeId);

Expand Down Expand Up @@ -154,7 +154,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {

getNodeIdsConnectedFrom(
nodeId: NodeId,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 0,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
): Array<NodeId> {
this._assertHasNodeId(nodeId);
let outboundByType = this.outboundEdges.getEdgesByType(nodeId);
Expand Down Expand Up @@ -211,7 +211,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
assert(wasRemoved);
}

removeEdges(nodeId: NodeId, type: TEdgeType | NullEdgeType = 0) {
removeEdges(nodeId: NodeId, type: TEdgeType | NullEdgeType = 1) {
this._assertHasNodeId(nodeId);

for (let to of this.outboundEdges.getEdges(nodeId, type)) {
Expand All @@ -223,7 +223,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
removeEdge(
from: NodeId,
to: NodeId,
type: TEdgeType | NullEdgeType = 0,
type: TEdgeType | NullEdgeType = 1,
removeOrphans: boolean = true,
) {
if (!this.outboundEdges.hasEdge(from, to, type)) {
Expand Down Expand Up @@ -295,7 +295,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
replaceNode(
fromNodeId: NodeId,
toNodeId: NodeId,
type: TEdgeType | NullEdgeType = 0,
type: TEdgeType | NullEdgeType = 1,
): void {
this._assertHasNodeId(fromNodeId);
for (let parent of this.inboundEdges.getEdges(fromNodeId, type)) {
Expand All @@ -310,7 +310,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
fromNodeId: NodeId,
toNodeIds: $ReadOnlyArray<NodeId>,
replaceFilter?: null | (NodeId => boolean),
type?: TEdgeType | NullEdgeType = 0,
type?: TEdgeType | NullEdgeType = 1,
): void {
this._assertHasNodeId(fromNodeId);

Expand All @@ -336,7 +336,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
traverse<TContext>(
visit: GraphVisitor<NodeId, TContext>,
startNodeId: ?NodeId,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 0,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
): ?TContext {
return this.dfs({
visit,
Expand All @@ -357,7 +357,7 @@ export default class Graph<TNode, TEdgeType: number = 0> {
traverseAncestors<TContext>(
startNodeId: ?NodeId,
visit: GraphVisitor<NodeId, TContext>,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 0,
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
): ?TContext {
return this.dfs({
visit,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/core/src/RequestTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import {
} from './constants';

export const requestGraphEdgeTypes = {
subrequest: 1,
invalidated_by_update: 2,
invalidated_by_delete: 3,
invalidated_by_create: 4,
invalidated_by_create_above: 5,
dirname: 6,
subrequest: 2,
invalidated_by_update: 3,
invalidated_by_delete: 4,
invalidated_by_create: 5,
invalidated_by_create_above: 6,
dirname: 7,
};

type RequestGraphEdgeType = $Values<typeof requestGraphEdgeTypes>;
Expand Down

0 comments on commit e85fc92

Please sign in to comment.