Skip to content

Commit

Permalink
Merge pull request #297 from KabukiStarship/Issue239
Browse files Browse the repository at this point in the history
 Map.Fix broken test #239
  • Loading branch information
CookingWithCale authored Sep 5, 2024
2 parents 5b2a932 + f37ae41 commit 9422f17
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 246 deletions.
15 changes: 9 additions & 6 deletions Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ the MPL was not distributed with this file, You can obtain one at
#ifndef SCRIPT2_ARRAY_TEMPLATES
#define SCRIPT2_ARRAY_TEMPLATES
#include "Array.h"
#include "Binary.hpp"
#include "Types.hpp"
namespace _ {

Expand Down Expand Up @@ -381,17 +382,19 @@ Printer& TArrayPrint(Printer& o, Autoject& obj) {
/* Inserts the given item at the start stack.
@pre You must perform bounds checking before calling this function. */
template<typename T>
inline void TArrayInsert_NC(T* items_start, T* items_end, T item) {
--items_end;
while (items_start < items_end) *items_end-- = *items_end;
*items_start = item;
inline void TArrayInsert_NC(T* items_start, T* items_stop, T item) {
while (items_start < items_stop) {
auto read = *(items_stop - 1);
*items_stop-- = read;
}
*items_stop = item;
}

/* Inserts the given item at the start stack.
@pre You must perform bounds checking before calling this function. */
template<typename T, typename ISZ>
inline void TArrayInsert_NC(T* elements, ISZ count_max, T item) {
return TArrayInsert_NC<T>(elements, elements + count_max, item);
inline void TArrayInsert_NC(T* elements, ISZ count, T item) {
return TArrayInsert_NC<T>(elements, elements + count, item);
}

/* Inserts the given item at the index index the elements of the given count.
Expand Down
55 changes: 14 additions & 41 deletions Book.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,14 @@ Printer& TBookPrint(Printer& o, const TBook<BOK_P>* book) {
auto voffsets = TPtr<ISZ>(book, sizeof(TBook<BOK_P>));
auto types = TPtr<DT>(voffsets + count_max);
auto keys_offset = *voffsets++;
auto keys = TPtr<TLoom<LOM_P>>(book, keys_offset);
#if D_THIS
TLoomPrint<COut, LOM_P>(o, keys);
#endif
auto keys = TPtr<TLoom<LOM_P>>(book, keys_offset);
auto keys_size = keys->size_bytes;
auto keys_top = keys->top;
D_COUT("\ncount_max:" << count_max << " count:" << count <<
" keys_size:" << keys_size << " keys_top : " << keys_top);
//D_AVOW(count_max, keys->map.count_max);
//D_AVOW(count , keys->map.count);
//TLoomPrint<COut, LOM_P>(StdOut(), keys);
D_AVOW(count_max, keys->map.count_max);
D_AVOW(count , keys->map.count);
D_COUT_LOOM(keys);
o << "\nBook<CH" << CATypeSWCH<CHT>() << ",IS" << CATypeSWCH<ISZ>() << ",IS"
<< CATypeSWCH<ISY>() << "> size_bytes:" << book->values.size_bytes
<< " count_max:" << count_max << " count:" << count << '\n'
Expand All @@ -230,7 +227,6 @@ Printer& TBookPrint(Printer& o, const TBook<BOK_P>* book) {
<< " values_free_space:" << TListFreeSpace<ISZ>(&book->values)
<< " keys.size_bytes:" << keys_size << " keys.top:" << keys_top
<< " TypeOf(keys):" << ATypef(types[0]) << ' ';
//TPrintATypeValue<Printer, DT>(o, *(types - 1), keys);
for (ISY i = 1; i < count; ++i) {
o << '\n' << i << ".) \"" << TLoomGet<LOM_P>(keys, i) << "\" type:";
auto type = *(++types);
Expand Down Expand Up @@ -307,9 +303,6 @@ TBook<BOK_P>* TBookInit(TBook<BOK_P>* book,
ISY keys_index = TListAlloc<LST_P>(values, KeysType, size_keys);
D_AVOW(ISY(0), keys_index);
D_COUT("\nkeys_index :" << keys_index);
//#if SEAM == SCRIPT2_BOOK
//TListPrint<COut, LST_P>(StdOut(), values);
//#endif
TLoom<LOM_P>* keys = TListValue<LST_P, TLoom<LOM_P>>(values, keys_index);
D_COUT("\nkeys offset : " << TDelta<>(book, keys) <<
"\nKeysType:0b" << Binaryf(KeysType) << ' ');
Expand All @@ -328,23 +321,13 @@ TBook<BOK_P>* TBookInit(TBook<BOK_P>* book,
D_COUT("\nkeys->top:" << keys->top);
D_COUT("\nTDelta<>(book, TBookKeys<BOK_P>(book)):" <<
TDelta<>(book, TBookKeys<BOK_P>(book)));
/*
#if SEAM == SCRIPT2_BOOK
D_COUT("\n\nValues:");
TListPrint<COut, LST_P>(StdOut(), values);
D_COUT("\n\nKeys:");
TLoomPrint<COut, LOM_P>(StdOut(), keys);
D_COUT(" free_space:" << TLoomFreeSpace<LOM_P>(keys));
#endif*/
if (!result) return nullptr;
D_COUT("\n\nTListInit Post size_bytes: " << size_bytes <<
" count_max:" << count_max <<
"\nBook End :" << TDelta<>(book, TBookEnd<BOK_P>(book)) <<
"\nKeys End :" << TDelta<>(book, TLoomEnd<LOM_P>(keys)) <<
"\nKeys Start:" << TDelta<>(book, keys) << "\n\nResult:\n");
#if D_THIS
TBookPrint<COut, BOK_P>(StdOut(), book);
#endif
D_COUT_BOOK(book);
return book;
}

Expand Down Expand Up @@ -463,22 +446,18 @@ inline ISY TBookInsert(TBook<BOK_P>* book, TLoom<LOM_P>* keys, const CHT* key,
if (result < 0) {
D_COUT("\n\n\nFailed to insert into loom:" << result << ' ' <<
CrabsErrorSTR(result));
#if D_THIS
TLoomPrint<COut, LOM_P>(StdOut(), keys);
TBookPrint<COut, BOK_P>(StdOut(), book);
#endif
D_COUT_LOOM(keys);
D_COUT_BOOK(book);
return -ErrorKeysBufferOverflow;
}
else {
//TLoomPrint<COut, LOM_P>(StdOut(), keys);
}
//D_COUT_LOOM(keys);
//D_COUT("\n\nBefore:\n" << Charsf(book, book->values.size_bytes));
result = TListInsert<LST_P>(&book->values, item, result);
if (result < 0) {
#if SEAM == SCRIPT2_BOOK
D_COUT("\nFailed to insert into List with error " << result << ':' <<
CrabsErrorSTR(result));
TListPrint<COut, LST_P>(StdOut(), &book->values);
D_COUT_LIST(&book->values);
D_COUT("\n\nList memory: &book->values.size_bytes:" << *&book->values.size_bytes << '\n');
D_COUT(Charsf(&book->values, &book->values.size_bytes));
//D_COUT("After:\n" << Charsf(book, book->values.size_bytes));
Expand Down Expand Up @@ -599,7 +578,7 @@ inline ISY TBookInsertFrom(TBook<BOK_P>* book, TLoom<LOM_P>* keys, const CHT* ke
//D_COUT("\n\nList memory before:\n" <<
// Charsf(&book->values, *&book->values.size_bytes));
auto result = TListInsert<LST_P>(&book->values, type, value, index);
/**/TListPrint<COut, LST_P>(COut().Star(), &book->values);
D_COUT_LIST(&book->values);
if (result < 0)
return result;
auto key_index = TLoomInsert<LOM_P>(keys, key, index);
Expand Down Expand Up @@ -643,9 +622,7 @@ TBook<BOK_P>* TBookAdd(TBook<BOK_P>* book, const TBook<BOK_P>* source) {
src_count = ISY(src_values->map.count);
D_COUT("\nAdding " << src_count << " of " << src_count_max <<
" max items...\nsource:\n");
#if D_THIS
TBookPrint<COut, BOK_P>(COut().Star(), source);
#endif
D_COUT_BOOK(source);
D_ASSERT(src_count >= 0 && src_count <= src_count_max && src_top > 0);
TLoom<LOM_P>* keys = TBookKeys<BOK_P>(book);
const TLoom<LOM_P>* src_keys = TBookKeys<BOK_P>(source);
Expand Down Expand Up @@ -710,7 +687,7 @@ BOL TBookGrow(Autoject& obj) {
D_COUT("\n\n\n*******\nsize_new:" << size_new <<
" count_max:" << count_max_new << " keys_size_new:" << keys_size_new);
D_COUT("\n\nBefore:\n");
TBookPrint<COut, BOK_P>(StdOut(), source);
D_COUT_BOOK(source);
D_COUT(Charsf(source, source->values.size_bytes));
#endif*/
IUW* origin_new = obj.ram(nullptr, size_new);
Expand All @@ -722,9 +699,7 @@ BOL TBookGrow(Autoject& obj) {
TBookAdd<BOK_P>(destination, source);
obj.origin = origin_new;
D_COUT("\n\nFinished growing. :-)\n\n");
#if SEAM == SCRIPT2_BOOK
TBookPrint<COut, BOK_P>(COut().Star(), TPtr<TBook<BOK_P>>(obj.origin));
#endif
D_COUT_BOOK(TPtr<TBook<BOK_P>>(obj.origin));
return true;
}

Expand Down Expand Up @@ -759,9 +734,7 @@ ISY TBookInsert(AArray<IUA, ISZ, BUF>& obj, const CHT* key, T item,
D_COUT("\n\n\nFailed to insert into book:" << result << ' ' <<
CrabsErrorSTR(result));
auto keys = TBookKeys<BOK_P>(TPtr<TBook<BOK_P>>(obj.This()));
#if D_THIS
TLoomPrint<COut, LOM_P>(COut().Star(), keys);
#endif
D_COUT_LOOM(keys);
}
D_COUT("\ndez nutz baby!!!");
D_COUT('\n');
Expand Down
4 changes: 1 addition & 3 deletions Dic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ inline ISY TDicInsert(TDic<TPARAMS>* dic, const CHT* key, T item,
// " into index:" << index);
if (index < 0) return index;
auto list = TDicList<TPARAMS>(dic);
#if DEBUG_THIS
TListPrint<COut, ISY>(list);
#endif
D_COUT_DIC(list);
ISY result = ISY(TListInsert<ISZ, DTB>(list, item));
if (result < 0) {
D_COUT("\nFailed to insert with error " << result << ':'
Expand Down
4 changes: 2 additions & 2 deletions List.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ inline ISY TListInsert(TList<LST_P>* list, DT type, const void* value,
D_COUT("\n\nInserting type:" << Typef(type) << ":0d" << type << ":0x" << Hexf(type));
auto align_mask = ATypeAlignMask(type);
if (index == count) {
TListPrint<COut, LST_P>(COut().Star(), list);
//TListPrint<COut, LST_P>(StdOut(), list);
auto result = TATypeWrite_NC<ISZ>(TPtr<>(list, top), TPtr<>(list, size_bytes),
type, value, align_mask);
if (result == 0) return -ErrorBufferOverflow;
Expand Down Expand Up @@ -759,7 +759,7 @@ inline ISY TListInsert(TList<LST_P>* list, DT type, const void* value,
template<LST_A>
inline ISY TListAlloc(TList<LST_P>* list, DT type, ISZ size_bytes,
ISY index = PSH) {
TPrintATypeDebug<COut>(COut().Star(), type);
//TPrintATypeDebug<COut>(StdOut(), type);
ISA align_mask = ATypeAlignMask(type);
auto top = TAlignUp<ISZ>(list->top, align_mask);
ISY count = ISY(list->map.count),
Expand Down
Loading

0 comments on commit 9422f17

Please sign in to comment.