Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TopologicalSort/TopologicalSort.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Platform>x64</Platform>
</PropertyGroup>
<ItemGroup>
Expand Down
22 changes: 19 additions & 3 deletions TopologicalSort/Version10.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Version 9:

open System
open System.Collections.Generic
open System.Numerics
open System.Runtime.CompilerServices
open FSharp.NativeInterop
open Microsoft.CodeAnalysis.CSharp
//open Microsoft.CodeAnalysis.CSharp
open Row


Expand Down Expand Up @@ -94,7 +95,12 @@ module Edge =
int edge
|> LanguagePrimitives.Int32WithMeasure<Units.Node>


let inline getSourceBatch (vedge: Vector<int64>) =
Vector.ShiftRightLogical(vedge, 32) |> Vector.AsVectorInt32

let inline getTargetBatch (vedge: Vector<int64>) =
vedge |> Vector.AsVectorInt32

type EdgeTracker (nodeCount: int) =
let bitsRequired = ((nodeCount * nodeCount) + 63) / 64
let values = Array.create bitsRequired 0UL
Expand All @@ -111,7 +117,15 @@ type EdgeTracker (nodeCount: int) =
let offset = location &&& 0x3F
let mask = 1UL <<< offset
b.Values[bucket] <- b.Values[bucket] ||| mask


member inline b.BatchAdd(edge: Vector<int64>) =
let sources = Edge.getSourceBatch edge
let targets = Edge.getTargetBatch edge
let location = sources * b.NodeCount + targets
let bucket = Vector.ShiftRightLogical(location, 6)
let offset = Vector.BitwiseAnd(location,0x3F|>Vector)
let mask = Vector.ShiftLeft(offset, 1) // ???
()
member inline b.Remove (edge: Edge) =
let source = Edge.getSource edge
let target = Edge.getTarget edge
Expand Down Expand Up @@ -291,6 +305,7 @@ let sort (graph: Graph) =

let remainingEdges = EdgeTracker (int sourceRanges.Length)

// TODO: BatchAdd
sourceEdges
|> Bar.iter remainingEdges.Add

Expand All @@ -308,6 +323,7 @@ let sort (graph: Graph) =
let noRemainingSources =
sourceRanges[targetNodeId]
|> Range.forall (fun sourceIndex ->
//TODO: BatchContains
remainingEdges.Contains sourceEdges[sourceIndex]
|> not
)
Expand Down