Comments (3)
the .free
field doesn't actually have anything to do with free() itself, just happens to be the name of that field, but the reason for it is so that you can assign the function that should be called to clean up all the node values, instead of iterating/freeing them all manually. There's no function to assign or anything though, just like this https://github.com/visionmedia/list/blob/master/test.c#L130. Likewise here's an example .match https://github.com/visionmedia/list/blob/master/test.c#L130 so you can filter values by some custom function
from list.
OMG! I totally get it. They're NULL 'stubs' or 'placeholders'.
It dawned on me that looking at your test.c
could provide some insight to how those fields were intended to be used. I was starting to understand when your reply came in and that just confirmed it. It's actually REALLY cool, providing an empty 'plug' where a consumer of your library or api can insert their own custom function to handle cleanup and comparisons. Very nice.
It just leaves me with two questions about the list_find()
and list_remove()
functions:
1.) both the list_remove()
and list_destroy()
functions call the .free
field, but they're not the same. destroy calls self->free(curr->val)
and remove calls self->free(node)
. Is there a reason these calls differ? The former passes the current node's value while the latter passes the node itself. I'm thinking that remove is just a singular form of destroy, shouldn't these two methods pass similar arguments to the .free
field?
2.) list_find()
is the only function using the .match
field. I'm confused by the conditional fallback. If no function has been attached to the .match
field, then a simple '==' comparison is performed on the passed in val and the current node's val. Won't this comparison always fail because it's comparing pointer values? The passed in val points to one thing and the current node's val points to something else. While the data in memory may be the "same" won't those pointer addresses always be different, causing the comparison to always return false?
from list.
Closing this issue as solved (given it wasn't an issue anyway).
from list.
Related Issues (17)
- freeing curr-val before curr HOT 4
- Default free function HOT 1
- list_t->free dox
- Add support for circular linked lists
- malloc free HOT 4
- after list_remove item is still available HOT 1
- Debian package HOT 1
- list_remove should check node to NULL HOT 3
- Configuration header for list.h HOT 3
- Error freeing items with link_remove() HOT 1
- shared library HOT 5
- Install with less generic names? HOT 4
- New release for 0.4.0 HOT 4
- Why not add LIST_FREE(node) in functions list_rpop() or list_lp()? HOT 1
- Detecting loops in linked lists HOT 1
- warning: comparison of integers of different signs HOT 1
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 list.