diff --git a/src/containers/pideque.h b/src/containers/pideque.h index ae063704..00eb0941 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -201,13 +201,7 @@ public: } return *this; } - PIDeque & reserve(size_t new_size) { - if (new_size <= pid_rsize) return *this; - size_t os = pid_size; - alloc(new_size, true); - pid_size = os; - return *this; - } + PIDeque & reserve(size_t new_size) {if (new_size <= pid_rsize) return *this; size_t os = pid_size; alloc(new_size, true); pid_size = os; return *this;} PIDeque & insert(size_t index, const T & v = T()) { bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); @@ -216,10 +210,11 @@ public: alloc(pid_size + 1, true); if (index < pid_size - 1) { size_t os = pid_size - index - 1; - memmove(&(pid_data[index + pid_start + 1]), &(pid_data[index + pid_start]), os * sizeof(T)); + memmove(&(pid_data[pid_start + index + 1]), &(pid_data[pid_start + index]), os * sizeof(T)); } } else { - alloc(pid_size + 1, false, -1); + pid_start--; + alloc(pid_size + 1, false); //piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<"; if (index > 0) memmove(&(pid_data[pid_start]), &(pid_data[pid_start + 1]), index * sizeof(T)); @@ -231,22 +226,20 @@ public: PIDeque & insert(size_t index, const PIDeque & other) { if (other.isEmpty()) return *this; bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); - //piCout << this << "insert" << dir << index << pid_size << pid_rsize << pid_start << " <- " << other.size() << "!<"; + //piCout << "insert" << dir << index << pid_size << pid_rsize << pid_start << "!<"; if (dir) { ssize_t os = pid_size - index; alloc(pid_size + other.pid_size, true); if (os > 0) - memmove(&(pid_data[index + pid_start + other.pid_size]), &(pid_data[index + pid_start]), os * sizeof(T)); + memmove(&(pid_data[pid_start + index + other.pid_size]), &(pid_data[pid_start + index]), os * sizeof(T)); } else { - //if (pid_start < other.pid_size) pid_start = 0; - //piCout << this << " insert offseted start ba" << pid_start << pid_size << pid_rsize; - alloc(pid_size + other.pid_size, false, -other.pid_size); - //piCout << this << " insert offseted start aa" << pid_start << pid_size << pid_rsize; - //piCout << this << " insert front" << pid_size << pid_rsize << pid_start << "!<"; + pid_start -= other.pid_size; + alloc(pid_size + other.pid_size, false); + //piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<"; if (index > 0) memmove(&(pid_data[pid_start]), &(pid_data[pid_start + other.pid_size]), index * sizeof(T)); } - //piCout << this << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!"; + //piCout << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!"; newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size); return *this; } @@ -258,10 +251,10 @@ public: return *this; } size_t os = pid_size - index - count; - deleteT(&(pid_data[index + pid_start]), count); + deleteT(&(pid_data[pid_start + index]), count); if (os <= index) { //if (true) { - if (os > 0) memmove(&(pid_data[index + pid_start]), &(pid_data[index + pid_start + count]), os * sizeof(T)); + if (os > 0) memmove(&(pid_data[pid_start + index]), &(pid_data[pid_start + index + count]), os * sizeof(T)); } else { if (index > 0) memmove(&(pid_data[pid_start + count]), &(pid_data[pid_start]), index * sizeof(T)); pid_start += count; @@ -334,11 +327,11 @@ private: elementNew(dst + i, src[i]); } inline T * newRaw(size_t s) { - //std::cout << std::dec << " ![("< (new 0x" << (llong)ret << ") ok]!" << std::endl; + //cout << std::hex << " > (new 0x" << (llong)ret << ") ok]!" << endl; return (T*)ret; } /*void reallocRawTemp(size_t s) { @@ -346,7 +339,7 @@ private: else pid_tdata = (T*)(realloc(pid_tdata, s * sizeof(T))); }*/ inline void deleteT(T * d, size_t sz) { - //std::cout << " ~[("<= 4 && pid_size < pid_rsize / 6) { + if (pid_size >= 4 && pid_size < pid_rsize / 4) { /*if (direction) { if (pid_start >= 4 && pid_start > pid_size + pid_size && pid_start > pid_rsize / 2) { piCout << (int)this << "checkMove" << direction << pid_start << (int)pid_data << pid_rsize << pid_size; @@ -385,18 +378,16 @@ private: pid_start = ssize_t(pid_rsize) - pid_size - pid_size; } }*/ - //printf("(%p) check move st=%d sz=%d rs=%d\n", this, pid_start, pid_size, pid_rsize); if (pid_start < pid_size + pid_size || pid_start > pid_rsize - pid_size - pid_size) { - ssize_t ns = (pid_rsize - pid_size) / 2; + size_t ns = (pid_rsize - pid_size) / 2; if (pid_start != ns) { - //printf("(%p) move %d -> %d\n", this, pid_start, ns); memmove(pid_data + ns, pid_data + pid_start, pid_size * sizeof(T)); pid_start = ns; } } } } - inline void alloc(size_t new_size, bool direction, ssize_t start_offset = 0) { // direction == true -> alloc forward + inline void alloc(size_t new_size, bool direction) { // direction == true -> alloc forward if (direction) { if (pid_start + new_size <= pid_rsize) { pid_size = new_size; @@ -406,46 +397,42 @@ private: pid_size = new_size; size_t as = asize(pid_start + new_size); if (as != pid_rsize) { - //printf("(%p) realloc %d -> %d (%p)\n", this, pid_rsize, as, pid_data); pid_data = (T*)(realloc(pid_data, as*sizeof(T))); pid_rsize = as; - //printf("(%p) realloc done (%p)\n", this, pid_data); } } else { - size_t as; - //piCout << "INS ba" << *this; - if (pid_start + start_offset < 0) - as = asize(pid_rsize - start_offset); - else as = pid_rsize; - //printf("%X alloc %d %d\n", this, pid_rsize, start_offset); - //printf("%X alloc %d %d %d %d %d %d\n", this, new_size, pid_size, pid_rsize, as, pid_start, start_offset); + size_t as = asize(piMax(new_size, pid_rsize) - pid_start); + //piCout << "alloc" << new_size << pid_size << pid_rsize << as << pid_start; + if (pid_start >= 0 && as <= pid_rsize) { + pid_size = new_size; + checkMove(direction); + return; + } + size_t os = pid_size; + pid_size = new_size; if (as > pid_rsize) { - //printf("%X alloc new size %d\n", this, as); + //piCout << "alloc new size" << as; //cout << std::hex << " ![("< 0 && pid_data != 0) { - //printf("%X copy from %p + %d to %p + %d %d el\n", this, pid_data, pid_start, td, ns, pid_size); - memcpy(td + ns, pid_data + pid_start, pid_size * sizeof(T)); + //piCout << "pid_start" << pid_start << (pid_start + ssize_t(as) - os); + ssize_t ost = pid_start, ns = 0; + if (ost < 0) {ns -= ost; ost = 0;} + pid_start += ssize_t(as) - os; + if (os > 0 && pid_data != 0) { + memcpy(td + pid_start + ns, pid_data + ost, os * sizeof(T)); deleteRaw(pid_data); } pid_data = td; pid_rsize = as; - pid_start = ns; - //piCout << "INS aa" << *this; } - pid_start += start_offset; - pid_size = new_size; - checkMove(direction); } //checkMove(direction); - //printf("%X alloc new start %d\n", this, pid_start); + //piCout << "alloc new start" << pid_start; } T * pid_data; volatile size_t pid_size, pid_rsize; - volatile ssize_t pid_start; + volatile size_t pid_start; }; #define __PIDEQUE_SIMPLE_TYPE__(T) \ diff --git a/src/io/pipeer.h b/src/io/pipeer.h index f85de1e5..c67c013b 100755 --- a/src/io/pipeer.h +++ b/src/io/pipeer.h @@ -67,6 +67,7 @@ public: PIString name; PIVector
addresses; int dist; + PIStringList neighbours; bool isNeighbour() const {return dist == 0;} int ping() const; @@ -80,7 +81,6 @@ public: PIString nearest_address; - PIStringList neighbours; int sync, cnt, trace; bool was_update; PISystemTime time; diff --git a/utils/system_daemon/main.cpp b/utils/system_daemon/main.cpp index d447ce32..7e2904a6 100755 --- a/utils/system_daemon/main.cpp +++ b/utils/system_daemon/main.cpp @@ -141,6 +141,7 @@ public: if (cur_peer >= 0 && cur_peer < daemon_.allPeers().size_s()) pi = daemon_.allPeers()[cur_peer]; peerinfo_tl->content << TileSimple::Row("Name: " + pi.name, CellFormat()); peerinfo_tl->content << TileSimple::Row("Addreses: " + PIString::fromNumber(pi.addresses.size()), CellFormat()); + peerinfo_tl->content << TileSimple::Row("Neighbours: " + pi.neighbours.join(", "), CellFormat()); piForeachC(PIPeer::PeerInfo::Address &a , pi.addresses) addrs_tl->content << TileList::Row(a.address + " | " + a.netmask + " | " + PIString::fromNumber(a.ping) + @@ -150,7 +151,7 @@ public: PIStringList peermap; piForeachC(PeerPair &p , daemon_._peerMap()) { PIString s = p.first + " | "; - piForeachC(PIPeer::PeerInfo * pp, p.second) s += "->" + pp->name; + piForeachCR(PIPeer::PeerInfo * pp, p.second) s += " -> " + pp->name; peermap << s; } piForeachC(PIString &s , peermap)