Dev C++ Autocomplete

May 12, 2014  The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks. Dev-C A free, portable, fast and simple C/C IDE. Tracker Code Forums Menu Create Ticket; View Stats; Milestone Help. Formatting Help #172 Request: Autocomplete-Predictive keywords, a help for novice. This tool is very attractive for novice and will make Dev-C more popular. Other free IDEs such as Eclipse, Netbeam, Visual Studio. The code completion doesn't get updated in real time when you're trying to access the classes on the other tab. It would be nice if you don't have to save the file every time you want the code completion to get updated on the other tab.

  • JqueryUI Tutorial
  • JqueryUI Interactions
  • JqueryUI Widgets
  • JqueryUI Effects
  • JqueryUI Utilities
  • JqueryUI Useful Resources
  • Selected Reading

Dev C++ AutocompleteC++

Auto completion is a mechanism frequently used in modern websites to provide the user with a list of suggestions for the beginning of the word, which he/she has typed in a text box. The user can then select an item from the list, which will be displayed in the input field. This feature prevents the user from having to enter an entire word or a set of words.

JQueryUI provides an autocomplete widget — a control that acts a lot like a <select> dropdown, but filters the choices to present only those that match what the user is typing into a control. jQueryUI provides the autocomplete() method to create a list of suggestions below the input field and adds new CSS classes to the elements concerned to give them the appropriate style.

Any field that can receive input can be converted into an Autocomplete, namely, <input> elements, <textarea> elements, and elements with the contenteditable attribute.

Syntax

The autocomplete() method can be used in two forms −

  • $(selector, context).autocomplete (options) Method

  • $(selector, context).autocomplete ('action', params) Method

$ (selector, context).autocomplete (options) Method

The autocomplete (options) method declares that an HTML <input> element must be managed as an input field that will be displayed above a list of suggestions. The options parameter is an object that specifies the behavior of the list of suggestions when the user is typing in the input field.

Syntax

You can provide one or more options at a time using Javascript object. If there are more than one options to be provided then you will separate them using a comma as follows −

The following table lists the different options that can be used with this method −

Sr.No.Option & Description
1appendTo

This option is used append an element to the menu. By default its value is null.

2autoFocus

This option when set to true, the first item of the menu will automatically be focused when the menu is shown. By default its value is false.

3delay

This option is an Integer representing number of milliseconds to wait before trying to obtain the matching values (as specified by the source option). This can help reduce thrashing when non-local data is being obtained by giving the user time to enter more characters before the search is initiated. By default its value is 300.

4disabled

This option if specified and true, the autocomplete widget is initially disabled. By default its value is false.

5minLength

The number of characters that must be entered before trying to obtain the matching values (as specified by the source option). This can prevent too large a value set from being presented when a few characters isn’t enough to whittle the set down to a reasonable level. By default its value is 1.

6position

This option identifies the position of the suggestions menu in relation to the associated input element. The of option defaults to the input element, but you can specify another element to position against. By default its value is { my: 'left top', at: 'left bottom', collision: 'none' }.

7source

This option specifies the manner in which the data that matches the input data is obtained. A value must be provided or the autocomplete widget won’t be created. By default its value is none; must be specified.

The following section will show you a few working examples of autocomplete widget functionality.

Default Functionality

The following example demonstrates a simple example of autocomplete widget functionality, passing no parameters to the autocomplete() method.

Dev

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you should see the following output. Now, you can play with the result −

Use of autoFocus

The following example demonstrates the usage of option autoFocus in the autocomplete widget of JqueryUI.

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −

Use of minLength and delay

The following example demonstrates the usage of two options minLength and delay in the autocomplete widget of JqueryUI.

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −

Use of Label

The following example demonstrates the usage of option label in the autocomplete widget of JqueryUI.

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −

Use of External Source

The following example demonstrates the use of external file for source option in the autocomplete widget of JqueryUI.

The file search.php is placed at the same location as the above file (autocompleteexample.html). Contents of search.php are as below −

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −

$ (selector, context).autocomplete ('action', params) Method

The autocomplete ('action', params) method can perform an action on the list of suggestions, such as show or hide. The action is specified as a String in the first argument (e.g., 'close' to hide the list). Check out the actions that can be passed, in the following table.

Dev C++ Online

Syntax

The following table lists the different actions that can be used with this method −

Sr.No.Action & Description
1close

This action hides the list of suggestions in the Autocomplete menu. This method does not accept any arguments.

2destroy

This action removes the autocomplete functionality. Lists of suggestions are deleted. This method does not accept any arguments.

3disable

This action disables the autocompletion mechanism. The list of suggestions no longer appears. This method does not accept any arguments.

4enable

This action reactivates the autocompletion mechanism. The list of suggestions will again be displayed. This method does not accept any arguments.

5option( optionName )

This action retrieves the value of the specified param optionName. This option corresponds to one of those used with autocomplete (options).

6option

This action gets an object containing key/value pairs representing the current autocomplete options hash.

7option( optionName, value )

This action sets the value of the autocomplete option associated with the specified optionName. The argument optionName is name of the option to be set and value is the value to be set for the option.

8option( options )

This action is sets one or more options for the autocomplete. The argument options is a map of option-value pairs to be set.

9search( [value ] )

This action searches for correspondence between the string value and the data source (specified in options.source). The minimum number of characters (indicated in options.minLength) must be reached in value, otherwise the search is not performed.

10widget

Retrieve the <ul> DOM element corresponding to the list of suggestions. This is an object of jQuery class that allows easy access to the list without using jQuery selectors.

Example

Now let us see an example using the actions from the above table. The following example demonstrates the use of option( optionName, value ) method.

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript, you must also see the following output −

Extension Points

The autocomplete widget can be extended as its built with the widget factory. When extending widgets, you have the ability to override or add to the behavior of existing methods. The following table lists methods that act as extension points with the same API stability as the plugin methods listed above.

Dev C Autocomplete Free

Sr.No.Method & Description
1_renderItem( ul, item )

This method controls the creation of each option in the widget's menu. This method creates a new <li> element, appends it to the menu and return it.

2_renderMenu( ul, items )

This method controls building the widget's menu.

3_resizeMenu()

This method controls sizing the menu before it is displayed.The menu element is available at this.menu.element. This method does not accept any arguments.

Event Management on Autocomplete Elements

In addition to the autocomplete (options) method which we saw in the previous sections, JqueryUI provides event methods which gets triggered for a particular event. These event methods are listed below −

Sr.No.Event Method & Description
1change(event, ui)

This event is triggered when the value of the <input> element is changed based upon a selection. When triggered, this event will always come after the close event is triggered.

2close(event, ui)

This event is triggered whenever the autocomplete menu closes.

3create(event, ui)

This event is triggered when the autocomplete is created.

4focus(event, ui)

This event is triggered whenever one of the menu choices receives focus. Unless canceled (for example, by returning false), the focused value is set into the <input> element.

5open(event, ui)

This event is triggered after the data has been readied and the menu is about to open.

6response(event, ui)

This event is triggered after a search completes, before the menu is shown. This event is always triggered when a search completes, even if the menu will not be shown because there are no results or the Autocomplete is disabled.

7search(event, ui)

This event is triggered after any delay and minLength criteria have been met, just before the mechanism specified by source is activated. If canceled, the search operation is aborted.

8select(event, ui)

This event is triggered when a value is selected from the autocomplete menu. Canceling this event prevents the value from being set into the <input> element (but doesn’t prevent the menu from closing).

Example

Dev C++ Autocomplete Plugin

The following example demonstrates the event method usage in autocomplete widgets. This example demonstrates the use of events focus, and select.

Dev C++ Enable Autocomplete

Let us save the above code in an HTML file autocompleteexample.htm and open it in a standard browser which supports javascript. You must also see the following output −

Dev C++ 5.11

  • Description

    • autocomplete c++ library from cpp-libface
    • modification
      • remove all dependencies(http-parser,libuv)
      • leave library only
      • adjust source tree
      • swtich default algorithm to 'BenderRMQ'
        • BenderRMQ
          • space cost O(n) (= 8n hidden cost), build cost O(n), query cost O(1) (= 10 hidden cost)
        • SparseTable
          • space cost O(nlogn) (=2nlogn hidden cost), build cost O(nlogn), query cost O(1) (=2 hidden cost)
      • refactoring for easy use : create~, import~, suggest~
    • theoretical background
  • Compilation

  • Input format

  • Test

  • Dev notes

    • BenderRMQ vs SparseTable
      • input file : 213m, 5464518 record
      • BenderRMQ
        • building time : 17s
        • memory : 659m ( x3 )
        • search time : 1m10s=70s -> 78064 qps
      • SparseTable
        • building time : 18s
        • memory : 938m ( x4.5 )
        • search time : 1m7s=67s -> 81559 qps