public void NameTable_can_save_and_load() { StringTable stringTable = new StringTable(); StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable); NameTable nameTable = new NameTable('.', stringTable); NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder); nameTableBuilder.GetOrAdd("a.b.c"); nameTableBuilder.GetOrAdd("a.b.d.e"); nameTableBuilder.GetOrAdd("a.f.g.h"); stringTable.SaveToFile(TemporaryDirectory, $"{nameof(StringTable)}.txt"); nameTable.SaveToFile(TemporaryDirectory, $"{nameof(NameTable)}.bin"); StringTable stringTable2 = new StringTable(); NameTable nameTable2 = new NameTable('.', stringTable2); stringTable2.LoadFromFile(TemporaryDirectory, $"{nameof(StringTable)}.txt"); nameTable2.LoadFromFile(TemporaryDirectory, $"{nameof(NameTable)}.bin"); XAssert.AreEqual(8, nameTable2.Count); XAssert.AreEqual("a", nameTable2.GetText(nameTable2.Ids.First())); XAssert.AreEqual("a.f.g.h", nameTable2.GetText(nameTable2.Ids.Last())); }
public void NameTable_can_store_three_complex_elements() { StringTable stringTable = new StringTable(); StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable); NameTable nameTable = new NameTable('.', stringTable); NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder); NameId id = nameTableBuilder.GetOrAdd("a.b.c"); NameId id2 = nameTableBuilder.GetOrAdd("a.b.d.e"); NameId id3 = nameTableBuilder.GetOrAdd("a.f.g.h"); XAssert.IsFalse(id.Equals(id2)); XAssert.IsFalse(id.Equals(id3)); XAssert.IsFalse(id2.Equals(id3)); XAssert.AreEqual("a.b.c", nameTable.GetText(id)); XAssert.AreEqual(5, nameTable.Length(id)); XAssert.AreEqual("a.b.d.e", nameTable.GetText(id2)); XAssert.AreEqual(7, nameTable.Length(id2)); XAssert.AreEqual("a.f.g.h", nameTable.GetText(id3)); XAssert.AreEqual(7, nameTable.Length(id3)); XAssert.AreEqual(8, nameTable.Count); XAssert.AreEqual(8, nameTable.Ids.Count()); }
/// <summary> /// Add a pip, when you are sure it's not already in the table. /// </summary> public PipId Add(long semiStableHash, string name, PipType pipType) { PipEntry entry = new PipEntry( semiStableHash, NameTableBuilder.GetOrAdd(name), pipType); return(((PipTable)ValueTable).Add(entry)); }
public void NameTable_can_store_one_complex_element() { StringTable stringTable = new StringTable(); StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable); NameTable nameTable = new NameTable('.', stringTable); NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder); NameId id = nameTableBuilder.GetOrAdd("a.b"); NameId id2 = nameTableBuilder.GetOrAdd("a.b"); XAssert.IsTrue(id.Equals(id2)); XAssert.AreEqual("a.b", nameTable.GetText(id)); XAssert.AreEqual(3, nameTable.Length(id)); XAssert.AreEqual(2, nameTable.Count); XAssert.AreEqual(2, nameTable.Ids.Count()); }
public void NameIndex_contains_all_names() { StringTable stringTable = new StringTable(); StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable); NameTable nameTable = new NameTable('.', stringTable); NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder); NameId id = nameTableBuilder.GetOrAdd("a.b.c"); NameId id2 = nameTableBuilder.GetOrAdd("a.b.d.e"); NameId id3 = nameTableBuilder.GetOrAdd("a.f.g.h"); NameIndex nameIndex = new NameIndex(nameTable); XAssert.AreEqual(8, nameIndex.Count); XAssert.AreEqual(3, nameIndex[id].Length); XAssert.AreEqual(4, nameIndex[id2].Length); XAssert.AreEqual(4, nameIndex[id3].Length); // We know these are the string IDs because string IDs get added as the names are constructed, // and we happened to add names with each successive atom in lexical order. StringId a = new StringId(1); StringId b = new StringId(2); StringId c = new StringId(3); StringId d = new StringId(4); StringId e = new StringId(5); StringId f = new StringId(6); StringId g = new StringId(7); StringId h = new StringId(8); XAssert.AreArraysEqual(new[] { a, b, c }, nameIndex.Enumerate(id).Select(entry => entry.Atom).ToArray(), true); XAssert.AreArraysEqual(new[] { a, b, d, e }, nameIndex.Enumerate(id2).Select(entry => entry.Atom).ToArray(), true); XAssert.AreArraysEqual(new[] { a, f, g, h }, nameIndex.Enumerate(id3).Select(entry => entry.Atom).ToArray(), true); }
/// <summary> /// Get or add an entry for the given file path. /// </summary> /// <remarks> /// If the entry already exists, the sizeInBytes value passed here will be ignored! /// The only time that value can be set is when adding a new file not previously recorded. /// TODO: consider failing if this happens? /// </remarks> public DirectoryId GetOrAdd( string directoryPath, PipId producerPip, ContentFlags contentFlags, bool isSharedOpaque, uint partialSealId) { DirectoryEntry entry = new DirectoryEntry( PathTableBuilder.GetOrAdd(directoryPath), producerPip, contentFlags, isSharedOpaque, partialSealId); return(GetOrAdd(entry)); }
/// <summary> /// Get or add an entry for the given file path. /// </summary> /// <remarks> /// If the entry already exists, the sizeInBytes value passed here will be ignored! /// The only time that value can be set is when adding a new file not previously recorded. /// TODO: consider failing if this happens? /// </remarks> public DirectoryId GetOrAdd(string directoryPath, PipId producerPip, ContentFlags contentFlags) { DirectoryEntry entry = new DirectoryEntry(PathTableBuilder.GetOrAdd(directoryPath), producerPip, contentFlags); return(GetOrAdd(entry)); }