• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:08
CEST 03:08
KST 10:08
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall10HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles2[BSL20] Non-Korean Championship 4x BSL + 4x China9Flash Announces Hiatus From ASL66Weekly Cups (June 23-29): Reynor in world title form?14FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
The GOAT ranking of GOAT rankings The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps [ASL19] Finals Recap: Standing Tall SC uni coach streams logging into betting site Flash Announces Hiatus From ASL
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China [BSL20] Grand Finals - Sunday 20:00 CET CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Summer Games Done Quick 2025! Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 706 users

The Big Programming Thread - Page 824

Forum Index > General Forum
Post a Reply
Prev 1 822 823 824 825 826 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 19:02 GMT
#16461
hey I'm tinkering with a little chat client that writes to stdout and gets server messages from stdin and I'm interacting with this through a QT gui that basically runs a Qprocess that gets the client as a process, reads the output and can write to the input. Now my problem is, how do I get a list of active users to the Qt window? I've only got the client input and output stream.

Do I make another process that gets the user list from the server and sends this back to the gui? That sounds somewhat complicated.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
Last Edited: 2017-01-03 19:45:27
January 03 2017 19:43 GMT
#16462
instead of interpreting all data from stdin and stdout as messages, use them as a comm channel that carries different types of data?


in json format:

{ "type": "message", "content": "hello!" } or

{ "type": "userList", "content": "Alice, John" }
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-03 19:53:16
January 03 2017 19:52 GMT
#16463
that's what I also thought about, but isn't that prone to bugs if someone would send a text message that accidentally has the wrong structure? (although probably unlikely)
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
January 03 2017 19:59 GMT
#16464
you would take everything the user typed literally and put it in content field, why would there be a bug?

this is similar to the way that all web requests work, only difference is you are using stdin/stdout instead of a tcp connection
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 20:15 GMT
#16465
yes, you're right. I was confused and thought that there might be a way how a user could act like he's sending a "userlist" message but that shouldn't be possible. I'll do that, thanks.
Manit0u
Profile Blog Joined August 2004
Poland17244 Posts
Last Edited: 2017-01-03 21:23:54
January 03 2017 21:16 GMT
#16466
On January 04 2017 02:27 tofucake wrote:
Old datatables was awful. New datatables is pretty nice


Have you ever tried them alongside materialize with responsive tables?

I'm living in a nightmare for the past few days. I've even solved the async mailer library being incompatible with user authentication library problem just to get out of this shit for a moment...

Edit:

I mean, why the fuck in this day and age they would go for changing the style attribute of column cells and setting their width in pixel values, along with absolute positioning everywhere? What in the actual fuck?! How am I supposed to work with this shit that just pretends to be responsive? (I'm using DataTables 1.10.10)

The funniest thing is, including the DataTables.responsive extras and doing responsive: true, in the set-up actually makes it worse.

Seriously, fuck that shit. Why don't front-end people rebel at such blatant violation of all good practices?
Time is precious. Waste it wisely.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-05 01:00:01
January 04 2017 23:54 GMT
#16467
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-01-05 01:26:55
January 05 2017 00:57 GMT
#16468
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?


I don't really understand your problem but everything you seem to be doing looks like enforcing a protocol for communicating within your network, and stuff like that already exists because it's common.

https://en.wikipedia.org/wiki/JSON-RPC
https://en.wikipedia.org/wiki/IRCd

Some of your other "problems" just seem like problems with C/C++ async design, which is to say pretty poor multi-threading - polling, disconnects, updates (assuming you're using C++ cause you used stdin).
There is no one like you in the universe.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 05 2017 01:19 GMT
#16469
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?

What language do you use? What methods do you use to "test" your sockets?
Usually a socket should tell you when the connection has been closed. In java, for example, a TCP socket will throw an exeption when it discovers the other side is unavailable.
Manit0u
Profile Blog Joined August 2004
Poland17244 Posts
Last Edited: 2017-01-05 16:33:52
January 05 2017 06:32 GMT
#16470
I've decided to screw DataTables and implement my own solution.

Everything now works, is a lot simpler, a lot more maintainable and more reusable. It's also more than 6x faster.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-05 19:43:53
January 05 2017 19:15 GMT
#16471
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-05 19:53:37
January 05 2017 19:52 GMT
#16472
On January 06 2017 04:15 travis wrote:
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)

What that website refers to as "search" is probably a contains check for a given element. "Does the data structure contain a particular element?". This is something that all hash-based data structures are particularly good at since they have been made exactly for this purpose.

If you want to iterate over all elements within a data structure nothing will ever beat an array in terms of performance. ArrayList in java is using an array in the background and thus very fast for iterations. However, the HashMap (not HashTable!) also uses an array (more or less. Its complicated) and isnt that much slower. It should usually not make any difference. Dont worry about it unless you actually encounter problems with performance or you are explicitly working on an algorithm which needs to perform well for millions of elements.

The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.

By the way: A HashSet is usually build by using a HashMap internally so it really doesnt matter. Even if the Set is build from scratch it probably does much of the same thing as the Map. The difference, if any, should be insignificant.
slmw
Profile Blog Joined October 2010
Finland233 Posts
January 06 2017 01:35 GMT
#16473
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 10:33 GMT
#16474
On January 06 2017 10:35 slmw wrote:
Show nested quote +
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.

It is true that the empty buckets have an impact on speed, but in the average case the number of empty buckets is usually not very big. It still is an array iteration though (assuming the regular java HashMap implementation of course) and those are relatively fast.

But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.
zf
Profile Joined April 2011
231 Posts
January 06 2017 11:27 GMT
#16475
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 12:39 GMT
#16476
On January 06 2017 20:27 zf wrote:
Show nested quote +
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.

But travis and I were talking about iterating all elements.
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-01-06 13:23:57
January 06 2017 13:05 GMT
#16477
Sorry, I meant binary search trees where most languages only provide an ordered iterator. I stand corrected.
Edit: Which is also O(N), so it's just the same as an in-order traversal of a tree. A few more steps involved than in iterating a linked list though.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-06 18:11:42
January 06 2017 17:18 GMT
#16478
edit:

i guess it would be rude to completely delete this. my question was about using recursion to find the smallest finite line segment among many finite line segments on a plane, that does not intersect any other line segments.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2017-01-06 17:45:05
January 06 2017 17:44 GMT
#16479
First of all you should sort your lines by length. There should be a sort-method readily available in Java, you might have to pass it a Comparer of sorts, which converts a line into its length. The result of this step is a sorted list of lines.

Then in the second step, you iterate over the sorted lines. For each line, you check it against all lines, which you do again by iterating over the sorted lines, skipping the one you're currently checking. If you find one that doesn't intersect any line, you return that one as a result. It is the smallest one because it's the first in the sorted list.

There is no recursion here. It's a naive approach, but clean and simple. It's O(n^2). More sophisticated approaches probably would keep the first part, but tweak the second part to use sort of a divide and conquer approach, but that won't be very simple at all. I can imagine O(n log n), but I don't know if it actually is possible.

This approach includes a number of pointless checks, in the worst case 50%. This is because I check against all lines without skipping the pairs already covered. We can avoid that easily by storing the sorted lines in a list, then iterate over the list by index. If we are currently at list[5], we only check against list[6] and beyond:

for(int i = 0; i < list.Count; ++i) {
for(int k = i + 1; k < list.Count; ++k) {
check if list[i] intersects list[k];
}
}
Still is O(n^2) though.

Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-06 19:11:13
January 06 2017 19:11 GMT
#16480
On January 07 2017 02:44 spinesheath wrote:
Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Another improvement would be to remove all lines that intersect any other line after each pass. This will make consecutive passes faster in a bad case with many intersecting lines. (in a case with few intersecting lines we will stop early anyways)

On January 07 2017 02:44 spinesheath wrote:
Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.

There is some Just-In-Time optimizations which unroll the recursion but those are not quite at the level of the magic functional programming languages do so I agree.
Prev 1 822 823 824 825 826 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
Korean StarCraft League #77
CranKy Ducklings119
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft404
Livibee 121
ProTech69
RuFF_SC2 54
Vindicta 14
StarCraft: Brood War
MaD[AoV]35
Bale 30
Icarus 4
Dota 2
monkeys_forever369
NeuroSwarm124
League of Legends
JimRising 609
Counter-Strike
summit1g10964
tarik_tv5375
taco 413
Super Smash Bros
Mew2King137
Other Games
shahzam904
Maynarde150
Day[9].tv122
ToD96
JuggernautJason95
Organizations
Other Games
gamesdonequick49546
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• HeavenSC 26
• davetesta25
• Berry_CruncH23
• Mapu3
• Kozan
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• Pr0nogo 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2652
League of Legends
• Jankos1484
• TFBlade562
• Stunt241
Other Games
• Scarra1671
• WagamamaTV189
• Day9tv122
Upcoming Events
Sparkling Tuna Cup
8h 52m
WardiTV European League
14h 52m
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
22h 52m
The PondCast
1d 8h
WardiTV European League
1d 10h
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
1d 14h
Replay Cast
1d 22h
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
2 days
RSL Revival
3 days
Classic vs Cure
[ Show More ]
FEL
3 days
RSL Revival
4 days
FEL
4 days
FEL
4 days
CSO Cup
4 days
BSL20 Non-Korean Champi…
4 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.