Add replace and updateSpans to SpanIndex.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-02-15 15:18:52 -07:00
parent 9324c5a7ee
commit f30f028868
2 changed files with 17 additions and 0 deletions

View File

@@ -5,6 +5,16 @@ describe "SpanIndex", ->
beforeEach ->
index = new SpanIndex
describe ".updateSpans(start, end, spans)", ->
it "updates the spans of a range of entries indicated by the given index to the given value", ->
index.insert(0, [3, 2, 3, 1, 2], ['a', 'b', 'c', 'd', 'e'])
index.updateSpans(1, 3, 1)
expect(index.spanForIndex(1)).toBe 3
expect(index.spanForIndex(2)).toBe 4
expect(index.spanForIndex(3)).toBe 5
expect(index.spanForIndex(4)).toBe 6
expect(index.spanForIndex(5)).toBe 8
describe ".sliceBySpan(start, end)", ->
describe "when the index contains values that start and end evenly on the given start/end span indices", ->
it "returns the spanning values with a start and end offset of 0", ->

View File

@@ -8,9 +8,16 @@ class SpanIndex
insert: (index, spans, values) ->
@entries[index..index] = @buildIndexEntries(spans, values)
replace: (index, span, value) ->
@splice(index, index, span, [value])
splice: (start, end, spans, values) ->
@entries[start..end] = @buildIndexEntries(spans, values)
updateSpans: (start, end, span) ->
for i in [start..end]
@entries[i].span = span
at: (index) ->
@entries[index].value