Skip to content

Commit

Permalink
pare down more useless namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Jan 31, 2024
1 parent 9567397 commit 8dffe24
Show file tree
Hide file tree
Showing 44 changed files with 384 additions and 296 deletions.
32 changes: 16 additions & 16 deletions Sources/LZ77/Deflator/LZ77.Deflator.Stream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ extension LZ77.Deflator
@frozen @usableFromInline
struct Stream
{
let format:LZ77.Format
let search:Search
let format:LZ77.DeflateFormat
let search:LZ77.DeflatorSearch

var input:In
var input:LZ77.DeflatorIn<LZ77.MRC32>
//var queued:(run:Int, extend:Int, distance:Int)?
//var terms:[Term]
var window:Window
var matches:Matches
var output:Out
var window:LZ77.DeflatorWindow
var matches:LZ77.DeflatorMatches
var output:LZ77.DeflatorOut

init(format:LZ77.Format, level:Int, exponent:Int, hint:Int)
init(format:LZ77.DeflateFormat, level:Int, exponent:Int, hint:Int)
{
precondition(8 ..< 16 ~= exponent,
"exponent cannot be less than 8 or greater than 15")
Expand Down Expand Up @@ -463,9 +463,9 @@ extension LZ77.Deflator.Stream
}

private mutating
func blockTables(_ metaterms:[LZ77.Deflator.Term.Meta], semistatic:LZ77.Deflator.Semistatic)
func blockTables(_ metaterms:[LZ77.DeflatorTerm.Meta], semistatic:LZ77.DeflatorTables)
{
for metaterm:LZ77.Deflator.Term.Meta in metaterms
for metaterm:LZ77.DeflatorTerm.Meta in metaterms
{
let codeword:LZ77.Codeword = semistatic[meta: metaterm.symbol]
self.output.append(codeword.bits, count: codeword.length)
Expand All @@ -474,14 +474,14 @@ extension LZ77.Deflator.Stream
}

private mutating
func blockCompressed(semistatic:LZ77.Deflator.Semistatic)
func blockCompressed(semistatic:LZ77.DeflatorTables)
{
switch self.search
{
case .greedy, .lazy:
for index:Int in self.matches.indices
{
let term:LZ77.Deflator.Term = .init(storage: self.matches[offset: index])
let term:LZ77.DeflatorTerm = .init(storage: self.matches[offset: index])

let symbol:(runliteral:UInt16, distance:UInt8) = term.symbol
let codeword:(runliteral:LZ77.Codeword, distance:LZ77.Codeword)
Expand Down Expand Up @@ -606,7 +606,7 @@ extension LZ77.Deflator.Stream
var repetitions:Int = 1,
last:UInt8 = lengths[0]
var iterator:ArraySlice<UInt8>.Iterator = lengths[1 ..< r + d].makeIterator(),
terms:[LZ77.Deflator.Term.Meta] = []
terms:[LZ77.DeflatorTerm.Meta] = []
while true
{
let current:UInt8? = iterator.next()
Expand Down Expand Up @@ -667,7 +667,7 @@ extension LZ77.Deflator.Stream

// construct metatree
var frequencies:[Int] = .init(repeating: 0, count: 19)
for term:LZ77.Deflator.Term.Meta in terms
for term:LZ77.DeflatorTerm.Meta in terms
{
frequencies[.init(term.symbol)] += 1
}
Expand All @@ -676,7 +676,7 @@ extension LZ77.Deflator.Stream

self.blockStart(final: final, runliterals: r, distances: d, metatree: tree.meta)

let semistatic:LZ77.Deflator.Semistatic = .init(
let semistatic:LZ77.DeflatorTables = .init(
runliteral: tree.runliteral,
distance: tree.distance,
meta: tree.meta)
Expand All @@ -693,7 +693,7 @@ extension LZ77.Deflator.Stream
/* private mutating
func block(_ index:Int, dicing:LZ77.Deflator.Dicing, last:Bool)
{
let semistatic:LZ77.Deflator.Semistatic,
let semistatic:LZ77.DeflatorTables,
range:Range<Int>
switch dicing[index]
{
Expand Down Expand Up @@ -767,7 +767,7 @@ extension LZ77.Deflator.Stream
mutating
func checksum()
{
if case .ios = self.format
if case .ios = self.format
{
return
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/LZ77/Deflator/LZ77.Deflator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension LZ77
extension LZ77.Deflator
{
public
init(format:LZ77.Format = .zlib, level:Int, exponent:Int = 15, hint:Int = 1 << 12)
init(format:LZ77.DeflateFormat = .zlib, level:Int, exponent:Int = 15, hint:Int = 1 << 12)
{
let e:Int
switch format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extension LZ77.Deflator.Dicing
extension LZ77.DeflatorDicing
{
enum Node
{
Expand All @@ -8,7 +8,7 @@ extension LZ77.Deflator.Dicing
codelengths:[UInt16],
runliterals:Int,
distances:Int,
metaterms:[LZ77.Deflator.Term.Meta],
metaterms:[LZ77.DeflatorTerm.Meta],
tree:
(
runliteral:LZ77.HuffmanTree<UInt16>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension LZ77.Deflator
extension LZ77
{
struct Dicing
struct DeflatorDicing
{
typealias Element = (weight:Int, node:Node)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
extension LZ77.Deflator
extension LZ77
{
@frozen @usableFromInline
struct In
struct DeflatorIn<Integral> where Integral:LZ77.StreamIntegral
{
private
var startIndex:Int,
endIndex:Int

private
var capacity:Int

private
var integral:Integral
private
var storage:ManagedBuffer<Void, UInt8>

private
var integral:LZ77.MRC32
}
}
extension LZ77.Deflator.In
{
init()
{
var capacity:Int = 0
self.storage = .create(minimumCapacity: 0)
init()
{
capacity = $0.capacity
var capacity:Int = 0
self.storage = .create(minimumCapacity: 0)
{
capacity = $0.capacity
}
// self.startIndex = 0
// self.endIndex = 0
self.startIndex = 4
self.endIndex = 4
self.capacity = capacity
self.integral = .init()
}
// self.startIndex = 0
// self.endIndex = 0
self.startIndex = 4
self.endIndex = 4
self.capacity = capacity

self.integral = .init()
}

}
extension LZ77.DeflatorIn
{
var count:Int
{
self.endIndex - self.startIndex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extension LZ77.Deflator.Matches
extension LZ77.DeflatorMatches
{
@frozen @usableFromInline
struct Depths
Expand All @@ -9,7 +9,7 @@ extension LZ77.Deflator.Matches
var generic:Bool
}
}
extension LZ77.Deflator.Matches.Depths
extension LZ77.DeflatorMatches.Depths
{
// depth table layout:
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extension LZ77.Deflator
extension LZ77
{
@frozen @usableFromInline
struct Matches
struct DeflatorMatches
{
private
var storage:ManagedBuffer<Void, UInt32>
Expand All @@ -16,7 +16,7 @@ extension LZ77.Deflator
var depths:Depths
}
}
extension LZ77.Deflator.Matches
extension LZ77.DeflatorMatches
{
// match buffer either contains a linear vector of LZ77 terms,
// or a directed graph.
Expand Down Expand Up @@ -115,7 +115,7 @@ extension LZ77.Deflator.Matches
assert(self.unfilled > 0)

self[offset: self.endIndex] =
LZ77.Deflator.Term.init(literal: literal).storage
LZ77.DeflatorTerm.init(literal: literal).storage
self.count += 1
}
mutating
Expand All @@ -124,7 +124,7 @@ extension LZ77.Deflator.Matches
assert(self.unfilled > 0)

self[offset: self.endIndex] =
LZ77.Deflator.Term.init(run: match.run, distance: match.distance).storage
LZ77.DeflatorTerm.init(run: match.run, distance: match.distance).storage
self.count += 1
}

Expand All @@ -140,7 +140,7 @@ extension LZ77.Deflator.Matches
var frequencies:[Int] = .init(repeating: 0, count: 320)
for index:Int in self.indices
{
let term:LZ77.Deflator.Term = .init(storage: self[offset: index])
let term:LZ77.DeflatorTerm = .init(storage: self[offset: index])
// no need to differentiate between literals and run-distance pairs,
// because literal terms have the distance symbol set to a non-
// existent symbol (32)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extension LZ77.Deflator
extension LZ77
{
@frozen @usableFromInline
struct Out
struct DeflatorOut
{
private
var capacity:Int, // units in atoms
Expand All @@ -27,7 +27,7 @@ extension LZ77.Deflator
}
}
}
extension LZ77.Deflator.Out
extension LZ77.DeflatorOut
{
var bytes:Int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extension LZ77.Deflator
extension LZ77
{
@frozen @usableFromInline
enum Search
enum DeflatorSearch
{
case greedy(attempts:Int, goal:Int)
case lazy(attempts:Int, goal:Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension LZ77.Deflator
extension LZ77
{
struct Semistatic
struct DeflatorTables
{
private
let storage:ManagedBuffer<Void, LZ77.Codeword>
Expand All @@ -21,9 +21,10 @@ extension LZ77.Deflator
// 339 └───────────────────────┘
}
}
extension LZ77.Deflator.Semistatic
extension LZ77.DeflatorTables
{
init(runliteral:LZ77.HuffmanTree<UInt16>, distance:LZ77.HuffmanTree<UInt8>,
init(runliteral:LZ77.HuffmanTree<UInt16>,
distance:LZ77.HuffmanTree<UInt8>,
meta:LZ77.HuffmanTree<UInt8>? = nil)
{
self.storage = .create(minimumCapacity: 339){ _ in () }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extension LZ77.Deflator.Term
extension LZ77.DeflatorTerm
{
struct Meta
{
Expand All @@ -8,7 +8,7 @@ extension LZ77.Deflator.Term
let storage:(symbol:UInt8, bits:UInt8)
}
}
extension LZ77.Deflator.Term.Meta
extension LZ77.DeflatorTerm.Meta
{
var symbol:UInt8
{
Expand Down Expand Up @@ -42,7 +42,7 @@ extension LZ77.Deflator.Term.Meta
}
}
}
extension LZ77.Deflator.Term.Meta:CustomStringConvertible
extension LZ77.DeflatorTerm.Meta:CustomStringConvertible
{
var description:String
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extension LZ77.Deflator
extension LZ77
{
struct Term
struct DeflatorTerm
{
let storage:UInt32
}
}
extension LZ77.Deflator.Term
extension LZ77.DeflatorTerm
{
// it takes about 28 bits to represent a length-distance pair, and
// we can save ourselves some branching by using the remaining 4
Expand Down Expand Up @@ -55,7 +55,7 @@ extension LZ77.Deflator.Term
self.storage = symbols | bits
}
}
extension LZ77.Deflator.Term:CustomStringConvertible
extension LZ77.DeflatorTerm:CustomStringConvertible
{
var description:String
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extension LZ77.Deflator.Window
extension LZ77.DeflatorWindow
{
@frozen @usableFromInline
struct Element
Expand Down
Loading

0 comments on commit 8dffe24

Please sign in to comment.