Comments (5)
Maybe we could keep the "cache" by having the count cached in the "head"-TLink too?
Of course any manual adjustment to "_head" is then borking the whole thing again. Also it smells a bit "dirty/hacked".
from brl.mod.
Yeah, may as well throw away the cache and do a full count every time - if someone wants to cache it they can implement their own version.
from brl.mod.
from brl.mod.
bump.
This is still valid.
It could be circumvented if a TLink would know about the list it is stored in (so it could invalidate the _count value).
With the new GC shouldn't a "circular reference" no longer create trouble?
Also: as TLink objects are just for TList and and nothing else we should be able to "guarantee" that they are just used there (but maybe referenced multiple times). I mean: a TLink is connected to a single List and not multiple.
from brl.mod.
Was about to create a new issue when I found this.
Since TList
manages the count itself at the moment ...
bbdoc: Remove an object from a linked list
about: Remove scans a list for the specified value and removes its link.
End Rem
Method Remove( value:Object )
Local link:TLink=FindLink( value )
If Not link Return False
link.Remove
If _count > -1 Then
_count :- 1
End If
Return True
End Method
... the link interface is misleading.
I found myself in a situation where I wanted to filter a list for a condition and then remove a value. This was easy by obtaining FirstLink()
and then calling link.Remove()
.
I think this is a problem, and would like to solve this one way or another. Since TLink#Remove
is public and seems useful, here's some ideas:
- Try to make the call impossible. Add a warning to the docs like "Do not call this!" and rename
Remove
to_Remove
and make this a more obvious programmer error. - Offer a better alternative. Add
RemoveLink
toTList
so you can work with the link and don't have to first search for the link, then iterate the list again to remove the value it represents. Can work together with (1). - Update list counters when removing links. E.g. make links unique per list, give lists an ID, and reference the source list by ID to avoid circular references. Upon removal, trigger an
Invalidate
event so the list updates its counter later if necessary. (That's be a lot of overhead and quite odd.) @GWRon's suggestion aligns with this: TLink has to be unique per list. - Do not cache the count. The time it takes to compute the count is O(n) instead of O(1) in that case, but an extension to
TList
with a cache added back in is simple. In fact, we could provide both.
I would prefer to go ahead and create a PR with a combination of (1), (2), and (4). :)
from brl.mod.
Related Issues (20)
- [brl.graphics] Duplicate use of Graphics() flag IDs
- [Brl.Socket] AF_UNSPEC_ usage in docs is wrong
- Some undefined behavior found in bbMilliSecs()
- brl.TStringbuilder; extended startsWith() HOT 1
- [graphics.mod] TGraphics.Resize() and .Position() only stubs HOT 2
- [blitz.mod] Expose MemSet() or extend MemClear() to allow specific values
- [gnet.mod] Handle invalid peer events and disconnect timeout
- io.mod/common.bmx identifier FromEpoch not found HOT 2
- Unhandled Exception:GNet error, ENET_EVENT_TYPE_RECEIVE with invalid peer HOT 6
- [glGraphics.mod] MacOS: Carbon API deprecated / not supported
- Issues with 'library callbacks' with a potential solution HOT 2
- [platform.mod] PhysicalProcessorCount() not working properly on Win32 HOT 3
- StackTrace path issue HOT 1
- add FileExists function or use FileSize =-1? also, one other thing HOT 2
- Memory leaks (bbMemAlloc & bbMemFree) HOT 10
- [brl.pixmap] Handling "noDebug" - with still catching "null objects"
- [blitz.mod] Debug builds: GCSuspend/GCResume for each "local block"
- [blitz.mod] Debug builds secretly reactivate the GC even once GCSuspend()-ed HOT 7
- [random.mod] Add Rand() overloads to support "float/double" too? HOT 2
- [map.mod] Single method to retrieve value and existence of passed key HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brl.mod.